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 |
| 54 | // - JSRegExp |
| 55 | // - JSFunction |
| 56 | // - GlobalObject |
| 57 | // - JSGlobalObject |
| 58 | // - JSBuiltinsObject |
| 59 | // - JSGlobalProxy |
| 60 | // - JSValue |
| 61 | // - JSMessageObject |
| 62 | // - JSProxy |
| 63 | // - JSFunctionProxy |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 64 | // - ByteArray |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 65 | // - ExternalArray |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 66 | // - ExternalPixelArray |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 67 | // - ExternalByteArray |
| 68 | // - ExternalUnsignedByteArray |
| 69 | // - ExternalShortArray |
| 70 | // - ExternalUnsignedShortArray |
| 71 | // - ExternalIntArray |
| 72 | // - ExternalUnsignedIntArray |
| 73 | // - ExternalFloatArray |
| 74 | // - FixedArray |
| 75 | // - DescriptorArray |
| 76 | // - HashTable |
| 77 | // - Dictionary |
| 78 | // - SymbolTable |
| 79 | // - CompilationCacheTable |
| 80 | // - CodeCacheHashTable |
| 81 | // - MapCache |
| 82 | // - Context |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 83 | // - JSFunctionResultCache |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 84 | // - SerializedScopeInfo |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 85 | // - String |
| 86 | // - SeqString |
| 87 | // - SeqAsciiString |
| 88 | // - SeqTwoByteString |
| 89 | // - ConsString |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 90 | // - ExternalString |
| 91 | // - ExternalAsciiString |
| 92 | // - ExternalTwoByteString |
| 93 | // - HeapNumber |
| 94 | // - Code |
| 95 | // - Map |
| 96 | // - Oddball |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 97 | // - Foreign |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 98 | // - SharedFunctionInfo |
| 99 | // - Struct |
| 100 | // - AccessorInfo |
| 101 | // - AccessCheckInfo |
| 102 | // - InterceptorInfo |
| 103 | // - CallHandlerInfo |
| 104 | // - TemplateInfo |
| 105 | // - FunctionTemplateInfo |
| 106 | // - ObjectTemplateInfo |
| 107 | // - Script |
| 108 | // - SignatureInfo |
| 109 | // - TypeSwitchInfo |
| 110 | // - DebugInfo |
| 111 | // - BreakPointInfo |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 112 | // - CodeCache |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 113 | // |
| 114 | // Formats of Object*: |
| 115 | // Smi: [31 bit signed int] 0 |
| 116 | // HeapObject: [32 bit direct pointer] (4 byte aligned) | 01 |
| 117 | // Failure: [30 bit signed int] 11 |
| 118 | |
| 119 | // Ecma-262 3rd 8.6.1 |
| 120 | enum PropertyAttributes { |
| 121 | NONE = v8::None, |
| 122 | READ_ONLY = v8::ReadOnly, |
| 123 | DONT_ENUM = v8::DontEnum, |
| 124 | DONT_DELETE = v8::DontDelete, |
| 125 | ABSENT = 16 // Used in runtime to indicate a property is absent. |
| 126 | // ABSENT can never be stored in or returned from a descriptor's attributes |
| 127 | // bitfield. It is only used as a return value meaning the attributes of |
| 128 | // a non-existent property. |
| 129 | }; |
| 130 | |
| 131 | namespace v8 { |
| 132 | namespace internal { |
| 133 | |
| 134 | |
| 135 | // PropertyDetails captures type and attributes for a property. |
| 136 | // They are used both in property dictionaries and instance descriptors. |
| 137 | class PropertyDetails BASE_EMBEDDED { |
| 138 | public: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 139 | PropertyDetails(PropertyAttributes attributes, |
| 140 | PropertyType type, |
| 141 | int index = 0) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 142 | ASSERT(type != EXTERNAL_ARRAY_TRANSITION); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 143 | ASSERT(TypeField::is_valid(type)); |
| 144 | ASSERT(AttributesField::is_valid(attributes)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 145 | ASSERT(StorageField::is_valid(index)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 146 | |
| 147 | value_ = TypeField::encode(type) |
| 148 | | AttributesField::encode(attributes) |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 149 | | StorageField::encode(index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 150 | |
| 151 | ASSERT(type == this->type()); |
| 152 | ASSERT(attributes == this->attributes()); |
| 153 | ASSERT(index == this->index()); |
| 154 | } |
| 155 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 156 | PropertyDetails(PropertyAttributes attributes, |
| 157 | PropertyType type, |
| 158 | ExternalArrayType array_type) { |
| 159 | ASSERT(type == EXTERNAL_ARRAY_TRANSITION); |
| 160 | ASSERT(TypeField::is_valid(type)); |
| 161 | ASSERT(AttributesField::is_valid(attributes)); |
| 162 | ASSERT(StorageField::is_valid(static_cast<int>(array_type))); |
| 163 | |
| 164 | value_ = TypeField::encode(type) |
| 165 | | AttributesField::encode(attributes) |
| 166 | | StorageField::encode(static_cast<int>(array_type)); |
| 167 | |
| 168 | ASSERT(type == this->type()); |
| 169 | ASSERT(attributes == this->attributes()); |
| 170 | ASSERT(array_type == this->array_type()); |
| 171 | } |
| 172 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 173 | // Conversion for storing details as Object*. |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 174 | explicit inline PropertyDetails(Smi* smi); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 175 | inline Smi* AsSmi(); |
| 176 | |
| 177 | PropertyType type() { return TypeField::decode(value_); } |
| 178 | |
| 179 | bool IsTransition() { |
| 180 | PropertyType t = type(); |
| 181 | ASSERT(t != INTERCEPTOR); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 182 | return t == MAP_TRANSITION || t == CONSTANT_TRANSITION || |
| 183 | t == EXTERNAL_ARRAY_TRANSITION; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | bool IsProperty() { |
| 187 | return type() < FIRST_PHANTOM_PROPERTY_TYPE; |
| 188 | } |
| 189 | |
| 190 | PropertyAttributes attributes() { return AttributesField::decode(value_); } |
| 191 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 192 | int index() { return StorageField::decode(value_); } |
| 193 | |
| 194 | ExternalArrayType array_type() { |
| 195 | ASSERT(type() == EXTERNAL_ARRAY_TRANSITION); |
| 196 | return static_cast<ExternalArrayType>(StorageField::decode(value_)); |
| 197 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 198 | |
| 199 | inline PropertyDetails AsDeleted(); |
| 200 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 201 | static bool IsValidIndex(int index) { |
| 202 | return StorageField::is_valid(index); |
| 203 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 204 | |
| 205 | bool IsReadOnly() { return (attributes() & READ_ONLY) != 0; } |
| 206 | bool IsDontDelete() { return (attributes() & DONT_DELETE) != 0; } |
| 207 | bool IsDontEnum() { return (attributes() & DONT_ENUM) != 0; } |
| 208 | bool IsDeleted() { return DeletedField::decode(value_) != 0;} |
| 209 | |
| 210 | // Bit fields in value_ (type, shift, size). Must be public so the |
| 211 | // constants can be embedded in generated code. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 212 | class TypeField: public BitField<PropertyType, 0, 4> {}; |
| 213 | class AttributesField: public BitField<PropertyAttributes, 4, 3> {}; |
| 214 | class DeletedField: public BitField<uint32_t, 7, 1> {}; |
| 215 | class StorageField: public BitField<uint32_t, 8, 32-8> {}; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 216 | |
| 217 | static const int kInitialIndex = 1; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 218 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 219 | private: |
| 220 | uint32_t value_; |
| 221 | }; |
| 222 | |
| 223 | |
| 224 | // Setter that skips the write barrier if mode is SKIP_WRITE_BARRIER. |
| 225 | enum WriteBarrierMode { SKIP_WRITE_BARRIER, UPDATE_WRITE_BARRIER }; |
| 226 | |
| 227 | |
| 228 | // PropertyNormalizationMode is used to specify whether to keep |
| 229 | // inobject properties when normalizing properties of a JSObject. |
| 230 | enum PropertyNormalizationMode { |
| 231 | CLEAR_INOBJECT_PROPERTIES, |
| 232 | KEEP_INOBJECT_PROPERTIES |
| 233 | }; |
| 234 | |
| 235 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 236 | // NormalizedMapSharingMode is used to specify whether a map may be shared |
| 237 | // by different objects with normalized properties. |
| 238 | enum NormalizedMapSharingMode { |
| 239 | UNIQUE_NORMALIZED_MAP, |
| 240 | SHARED_NORMALIZED_MAP |
| 241 | }; |
| 242 | |
| 243 | |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 244 | // Instance size sentinel for objects of variable size. |
| 245 | static const int kVariableSizeSentinel = 0; |
| 246 | |
| 247 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 248 | // All Maps have a field instance_type containing a InstanceType. |
| 249 | // It describes the type of the instances. |
| 250 | // |
| 251 | // As an example, a JavaScript object is a heap object and its map |
| 252 | // instance_type is JS_OBJECT_TYPE. |
| 253 | // |
| 254 | // The names of the string instance types are intended to systematically |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 255 | // mirror their encoding in the instance_type field of the map. The default |
| 256 | // encoding is considered TWO_BYTE. It is not mentioned in the name. ASCII |
| 257 | // encoding is mentioned explicitly in the name. Likewise, the default |
| 258 | // representation is considered sequential. It is not mentioned in the |
| 259 | // name. The other representations (eg, CONS, EXTERNAL) are explicitly |
| 260 | // mentioned. Finally, the string is either a SYMBOL_TYPE (if it is a |
| 261 | // symbol) or a STRING_TYPE (if it is not a symbol). |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 262 | // |
| 263 | // NOTE: The following things are some that depend on the string types having |
| 264 | // instance_types that are less than those of all other types: |
| 265 | // HeapObject::Size, HeapObject::IterateBody, the typeof operator, and |
| 266 | // Object::IsString. |
| 267 | // |
| 268 | // NOTE: Everything following JS_VALUE_TYPE is considered a |
| 269 | // JSObject for GC purposes. The first four entries here have typeof |
| 270 | // 'object', whereas JS_FUNCTION_TYPE has typeof 'function'. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 271 | #define INSTANCE_TYPE_LIST_ALL(V) \ |
| 272 | V(SYMBOL_TYPE) \ |
| 273 | V(ASCII_SYMBOL_TYPE) \ |
| 274 | V(CONS_SYMBOL_TYPE) \ |
| 275 | V(CONS_ASCII_SYMBOL_TYPE) \ |
| 276 | V(EXTERNAL_SYMBOL_TYPE) \ |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 277 | V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 278 | V(EXTERNAL_ASCII_SYMBOL_TYPE) \ |
| 279 | V(STRING_TYPE) \ |
| 280 | V(ASCII_STRING_TYPE) \ |
| 281 | V(CONS_STRING_TYPE) \ |
| 282 | V(CONS_ASCII_STRING_TYPE) \ |
| 283 | V(EXTERNAL_STRING_TYPE) \ |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 284 | V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 285 | V(EXTERNAL_ASCII_STRING_TYPE) \ |
| 286 | V(PRIVATE_EXTERNAL_ASCII_STRING_TYPE) \ |
| 287 | \ |
| 288 | V(MAP_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 289 | V(CODE_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 290 | V(ODDBALL_TYPE) \ |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 291 | V(JS_GLOBAL_PROPERTY_CELL_TYPE) \ |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 292 | \ |
| 293 | V(HEAP_NUMBER_TYPE) \ |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 294 | V(FOREIGN_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 295 | V(BYTE_ARRAY_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 296 | /* Note: the order of these external array */ \ |
| 297 | /* types is relied upon in */ \ |
| 298 | /* Object::IsExternalArray(). */ \ |
| 299 | V(EXTERNAL_BYTE_ARRAY_TYPE) \ |
| 300 | V(EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE) \ |
| 301 | V(EXTERNAL_SHORT_ARRAY_TYPE) \ |
| 302 | V(EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE) \ |
| 303 | V(EXTERNAL_INT_ARRAY_TYPE) \ |
| 304 | V(EXTERNAL_UNSIGNED_INT_ARRAY_TYPE) \ |
| 305 | V(EXTERNAL_FLOAT_ARRAY_TYPE) \ |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 306 | V(EXTERNAL_PIXEL_ARRAY_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 307 | V(FILLER_TYPE) \ |
| 308 | \ |
| 309 | V(ACCESSOR_INFO_TYPE) \ |
| 310 | V(ACCESS_CHECK_INFO_TYPE) \ |
| 311 | V(INTERCEPTOR_INFO_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 312 | V(CALL_HANDLER_INFO_TYPE) \ |
| 313 | V(FUNCTION_TEMPLATE_INFO_TYPE) \ |
| 314 | V(OBJECT_TEMPLATE_INFO_TYPE) \ |
| 315 | V(SIGNATURE_INFO_TYPE) \ |
| 316 | V(TYPE_SWITCH_INFO_TYPE) \ |
| 317 | V(SCRIPT_TYPE) \ |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 318 | V(CODE_CACHE_TYPE) \ |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 319 | V(POLYMORPHIC_CODE_CACHE_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 320 | \ |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 321 | V(FIXED_ARRAY_TYPE) \ |
| 322 | V(SHARED_FUNCTION_INFO_TYPE) \ |
| 323 | \ |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 324 | V(JS_MESSAGE_OBJECT_TYPE) \ |
| 325 | \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 326 | V(JS_VALUE_TYPE) \ |
| 327 | V(JS_OBJECT_TYPE) \ |
| 328 | V(JS_CONTEXT_EXTENSION_OBJECT_TYPE) \ |
| 329 | V(JS_GLOBAL_OBJECT_TYPE) \ |
| 330 | V(JS_BUILTINS_OBJECT_TYPE) \ |
| 331 | V(JS_GLOBAL_PROXY_TYPE) \ |
| 332 | V(JS_ARRAY_TYPE) \ |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 333 | V(JS_PROXY_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 334 | V(JS_REGEXP_TYPE) \ |
| 335 | \ |
| 336 | V(JS_FUNCTION_TYPE) \ |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 337 | V(JS_FUNCTION_PROXY_TYPE) \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 338 | |
| 339 | #ifdef ENABLE_DEBUGGER_SUPPORT |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 340 | #define INSTANCE_TYPE_LIST_DEBUGGER(V) \ |
| 341 | V(DEBUG_INFO_TYPE) \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 342 | V(BREAK_POINT_INFO_TYPE) |
| 343 | #else |
| 344 | #define INSTANCE_TYPE_LIST_DEBUGGER(V) |
| 345 | #endif |
| 346 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 347 | #define INSTANCE_TYPE_LIST(V) \ |
| 348 | INSTANCE_TYPE_LIST_ALL(V) \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 349 | INSTANCE_TYPE_LIST_DEBUGGER(V) |
| 350 | |
| 351 | |
| 352 | // Since string types are not consecutive, this macro is used to |
| 353 | // iterate over them. |
| 354 | #define STRING_TYPE_LIST(V) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 355 | V(SYMBOL_TYPE, \ |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 356 | kVariableSizeSentinel, \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 357 | symbol, \ |
| 358 | Symbol) \ |
| 359 | V(ASCII_SYMBOL_TYPE, \ |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 360 | kVariableSizeSentinel, \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 361 | ascii_symbol, \ |
| 362 | AsciiSymbol) \ |
| 363 | V(CONS_SYMBOL_TYPE, \ |
| 364 | ConsString::kSize, \ |
| 365 | cons_symbol, \ |
| 366 | ConsSymbol) \ |
| 367 | V(CONS_ASCII_SYMBOL_TYPE, \ |
| 368 | ConsString::kSize, \ |
| 369 | cons_ascii_symbol, \ |
| 370 | ConsAsciiSymbol) \ |
| 371 | V(EXTERNAL_SYMBOL_TYPE, \ |
| 372 | ExternalTwoByteString::kSize, \ |
| 373 | external_symbol, \ |
| 374 | ExternalSymbol) \ |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 375 | V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE, \ |
| 376 | ExternalTwoByteString::kSize, \ |
| 377 | external_symbol_with_ascii_data, \ |
| 378 | ExternalSymbolWithAsciiData) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 379 | V(EXTERNAL_ASCII_SYMBOL_TYPE, \ |
| 380 | ExternalAsciiString::kSize, \ |
| 381 | external_ascii_symbol, \ |
| 382 | ExternalAsciiSymbol) \ |
| 383 | V(STRING_TYPE, \ |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 384 | kVariableSizeSentinel, \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 385 | string, \ |
| 386 | String) \ |
| 387 | V(ASCII_STRING_TYPE, \ |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 388 | kVariableSizeSentinel, \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 389 | ascii_string, \ |
| 390 | AsciiString) \ |
| 391 | V(CONS_STRING_TYPE, \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 392 | ConsString::kSize, \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 393 | cons_string, \ |
| 394 | ConsString) \ |
| 395 | V(CONS_ASCII_STRING_TYPE, \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 396 | ConsString::kSize, \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 397 | cons_ascii_string, \ |
| 398 | ConsAsciiString) \ |
| 399 | V(EXTERNAL_STRING_TYPE, \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 400 | ExternalTwoByteString::kSize, \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 401 | external_string, \ |
| 402 | ExternalString) \ |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 403 | V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE, \ |
| 404 | ExternalTwoByteString::kSize, \ |
| 405 | external_string_with_ascii_data, \ |
| 406 | ExternalStringWithAsciiData) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 407 | V(EXTERNAL_ASCII_STRING_TYPE, \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 408 | ExternalAsciiString::kSize, \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 409 | external_ascii_string, \ |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 410 | ExternalAsciiString) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 411 | |
| 412 | // A struct is a simple object a set of object-valued fields. Including an |
| 413 | // object type in this causes the compiler to generate most of the boilerplate |
| 414 | // code for the class including allocation and garbage collection routines, |
| 415 | // casts and predicates. All you need to define is the class, methods and |
| 416 | // object verification routines. Easy, no? |
| 417 | // |
| 418 | // Note that for subtle reasons related to the ordering or numerical values of |
| 419 | // type tags, elements in this list have to be added to the INSTANCE_TYPE_LIST |
| 420 | // manually. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 421 | #define STRUCT_LIST_ALL(V) \ |
| 422 | V(ACCESSOR_INFO, AccessorInfo, accessor_info) \ |
| 423 | V(ACCESS_CHECK_INFO, AccessCheckInfo, access_check_info) \ |
| 424 | V(INTERCEPTOR_INFO, InterceptorInfo, interceptor_info) \ |
| 425 | V(CALL_HANDLER_INFO, CallHandlerInfo, call_handler_info) \ |
| 426 | V(FUNCTION_TEMPLATE_INFO, FunctionTemplateInfo, function_template_info) \ |
| 427 | V(OBJECT_TEMPLATE_INFO, ObjectTemplateInfo, object_template_info) \ |
| 428 | V(SIGNATURE_INFO, SignatureInfo, signature_info) \ |
| 429 | V(TYPE_SWITCH_INFO, TypeSwitchInfo, type_switch_info) \ |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 430 | V(SCRIPT, Script, script) \ |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 431 | V(CODE_CACHE, CodeCache, code_cache) \ |
| 432 | V(POLYMORPHIC_CODE_CACHE, PolymorphicCodeCache, polymorphic_code_cache) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 433 | |
| 434 | #ifdef ENABLE_DEBUGGER_SUPPORT |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 435 | #define STRUCT_LIST_DEBUGGER(V) \ |
| 436 | V(DEBUG_INFO, DebugInfo, debug_info) \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 437 | V(BREAK_POINT_INFO, BreakPointInfo, break_point_info) |
| 438 | #else |
| 439 | #define STRUCT_LIST_DEBUGGER(V) |
| 440 | #endif |
| 441 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 442 | #define STRUCT_LIST(V) \ |
| 443 | STRUCT_LIST_ALL(V) \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 444 | STRUCT_LIST_DEBUGGER(V) |
| 445 | |
| 446 | // We use the full 8 bits of the instance_type field to encode heap object |
| 447 | // instance types. The high-order bit (bit 7) is set if the object is not a |
| 448 | // string, and cleared if it is a string. |
| 449 | const uint32_t kIsNotStringMask = 0x80; |
| 450 | const uint32_t kStringTag = 0x0; |
| 451 | const uint32_t kNotStringTag = 0x80; |
| 452 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 453 | // Bit 6 indicates that the object is a symbol (if set) or not (if cleared). |
| 454 | // There are not enough types that the non-string types (with bit 7 set) can |
| 455 | // have bit 6 set too. |
| 456 | const uint32_t kIsSymbolMask = 0x40; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 457 | const uint32_t kNotSymbolTag = 0x0; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 458 | const uint32_t kSymbolTag = 0x40; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 459 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 460 | // If bit 7 is clear then bit 2 indicates whether the string consists of |
| 461 | // two-byte characters or one-byte characters. |
| 462 | const uint32_t kStringEncodingMask = 0x4; |
| 463 | const uint32_t kTwoByteStringTag = 0x0; |
| 464 | const uint32_t kAsciiStringTag = 0x4; |
| 465 | |
| 466 | // If bit 7 is clear, the low-order 2 bits indicate the representation |
| 467 | // of the string. |
| 468 | const uint32_t kStringRepresentationMask = 0x03; |
| 469 | enum StringRepresentationTag { |
| 470 | kSeqStringTag = 0x0, |
| 471 | kConsStringTag = 0x1, |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 472 | kExternalStringTag = 0x2 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 473 | }; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 474 | const uint32_t kIsConsStringMask = 0x1; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 475 | |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 476 | // If bit 7 is clear, then bit 3 indicates whether this two-byte |
| 477 | // string actually contains ascii data. |
| 478 | const uint32_t kAsciiDataHintMask = 0x08; |
| 479 | const uint32_t kAsciiDataHintTag = 0x08; |
| 480 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 481 | |
| 482 | // A ConsString with an empty string as the right side is a candidate |
| 483 | // for being shortcut by the garbage collector unless it is a |
| 484 | // symbol. It's not common to have non-flat symbols, so we do not |
| 485 | // shortcut them thereby avoiding turning symbols into strings. See |
| 486 | // heap.cc and mark-compact.cc. |
| 487 | const uint32_t kShortcutTypeMask = |
| 488 | kIsNotStringMask | |
| 489 | kIsSymbolMask | |
| 490 | kStringRepresentationMask; |
| 491 | const uint32_t kShortcutTypeTag = kConsStringTag; |
| 492 | |
| 493 | |
| 494 | enum InstanceType { |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 495 | // String types. |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 496 | SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kSeqStringTag, |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 497 | ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kSeqStringTag, |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 498 | CONS_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kConsStringTag, |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 499 | CONS_ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kConsStringTag, |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 500 | EXTERNAL_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kExternalStringTag, |
| 501 | EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE = |
| 502 | kTwoByteStringTag | kSymbolTag | kExternalStringTag | kAsciiDataHintTag, |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 503 | EXTERNAL_ASCII_SYMBOL_TYPE = |
| 504 | kAsciiStringTag | kSymbolTag | kExternalStringTag, |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 505 | STRING_TYPE = kTwoByteStringTag | kSeqStringTag, |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 506 | ASCII_STRING_TYPE = kAsciiStringTag | kSeqStringTag, |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 507 | CONS_STRING_TYPE = kTwoByteStringTag | kConsStringTag, |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 508 | CONS_ASCII_STRING_TYPE = kAsciiStringTag | kConsStringTag, |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 509 | EXTERNAL_STRING_TYPE = kTwoByteStringTag | kExternalStringTag, |
| 510 | EXTERNAL_STRING_WITH_ASCII_DATA_TYPE = |
| 511 | kTwoByteStringTag | kExternalStringTag | kAsciiDataHintTag, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 512 | // LAST_STRING_TYPE |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 513 | EXTERNAL_ASCII_STRING_TYPE = kAsciiStringTag | kExternalStringTag, |
| 514 | PRIVATE_EXTERNAL_ASCII_STRING_TYPE = EXTERNAL_ASCII_STRING_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 515 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 516 | // Objects allocated in their own spaces (never in new space). |
| 517 | MAP_TYPE = kNotStringTag, // FIRST_NONSTRING_TYPE |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 518 | CODE_TYPE, |
| 519 | ODDBALL_TYPE, |
| 520 | JS_GLOBAL_PROPERTY_CELL_TYPE, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 521 | |
| 522 | // "Data", objects that cannot contain non-map-word pointers to heap |
| 523 | // objects. |
| 524 | HEAP_NUMBER_TYPE, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 525 | FOREIGN_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 526 | BYTE_ARRAY_TYPE, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 527 | EXTERNAL_BYTE_ARRAY_TYPE, // FIRST_EXTERNAL_ARRAY_TYPE |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 528 | EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE, |
| 529 | EXTERNAL_SHORT_ARRAY_TYPE, |
| 530 | EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE, |
| 531 | EXTERNAL_INT_ARRAY_TYPE, |
| 532 | EXTERNAL_UNSIGNED_INT_ARRAY_TYPE, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 533 | EXTERNAL_FLOAT_ARRAY_TYPE, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 534 | EXTERNAL_DOUBLE_ARRAY_TYPE, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 535 | EXTERNAL_PIXEL_ARRAY_TYPE, // LAST_EXTERNAL_ARRAY_TYPE |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 536 | FIXED_DOUBLE_ARRAY_TYPE, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 537 | FILLER_TYPE, // LAST_DATA_TYPE |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 538 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 539 | // Structs. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 540 | ACCESSOR_INFO_TYPE, |
| 541 | ACCESS_CHECK_INFO_TYPE, |
| 542 | INTERCEPTOR_INFO_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 543 | CALL_HANDLER_INFO_TYPE, |
| 544 | FUNCTION_TEMPLATE_INFO_TYPE, |
| 545 | OBJECT_TEMPLATE_INFO_TYPE, |
| 546 | SIGNATURE_INFO_TYPE, |
| 547 | TYPE_SWITCH_INFO_TYPE, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 548 | SCRIPT_TYPE, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 549 | CODE_CACHE_TYPE, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 550 | POLYMORPHIC_CODE_CACHE_TYPE, |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 551 | // The following two instance types are only used when ENABLE_DEBUGGER_SUPPORT |
| 552 | // is defined. However as include/v8.h contain some of the instance type |
| 553 | // constants always having them avoids them getting different numbers |
| 554 | // depending on whether ENABLE_DEBUGGER_SUPPORT is defined or not. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 555 | DEBUG_INFO_TYPE, |
| 556 | BREAK_POINT_INFO_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 557 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 558 | FIXED_ARRAY_TYPE, |
| 559 | SHARED_FUNCTION_INFO_TYPE, |
| 560 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 561 | JS_MESSAGE_OBJECT_TYPE, |
| 562 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 563 | JS_VALUE_TYPE, // FIRST_NON_CALLABLE_OBJECT_TYPE, FIRST_JS_RECEIVER_TYPE |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 564 | JS_OBJECT_TYPE, |
| 565 | JS_CONTEXT_EXTENSION_OBJECT_TYPE, |
| 566 | JS_GLOBAL_OBJECT_TYPE, |
| 567 | JS_BUILTINS_OBJECT_TYPE, |
| 568 | JS_GLOBAL_PROXY_TYPE, |
| 569 | JS_ARRAY_TYPE, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 570 | JS_PROXY_TYPE, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 571 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 572 | JS_REGEXP_TYPE, // LAST_NONCALLABLE_SPEC_OBJECT_TYPE |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 573 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 574 | JS_FUNCTION_TYPE, // FIRST_CALLABLE_SPEC_OBJECT_TYPE |
| 575 | JS_FUNCTION_PROXY_TYPE, // LAST_CALLABLE_SPEC_OBJECT_TYPE |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 576 | |
| 577 | // Pseudo-types |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 578 | FIRST_TYPE = 0x0, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 579 | LAST_TYPE = JS_FUNCTION_PROXY_TYPE, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 580 | INVALID_TYPE = FIRST_TYPE - 1, |
| 581 | FIRST_NONSTRING_TYPE = MAP_TYPE, |
| 582 | // Boundaries for testing for an external array. |
| 583 | FIRST_EXTERNAL_ARRAY_TYPE = EXTERNAL_BYTE_ARRAY_TYPE, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 584 | LAST_EXTERNAL_ARRAY_TYPE = EXTERNAL_PIXEL_ARRAY_TYPE, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 585 | // Boundary for promotion to old data space/old pointer space. |
| 586 | LAST_DATA_TYPE = FILLER_TYPE, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 587 | // Boundary for objects represented as JSReceiver (i.e. JSObject or JSProxy). |
| 588 | // Note that there is no range for JSObject or JSProxy, since their subtypes |
| 589 | // are not continuous in this enum! The enum ranges instead reflect the |
| 590 | // external class names, where proxies are treated as either ordinary objects, |
| 591 | // or functions. |
| 592 | FIRST_JS_RECEIVER_TYPE = JS_VALUE_TYPE, |
| 593 | LAST_JS_RECEIVER_TYPE = LAST_TYPE, |
| 594 | // Boundaries for testing the types for which typeof is "object". |
| 595 | FIRST_NONCALLABLE_SPEC_OBJECT_TYPE = JS_VALUE_TYPE, |
| 596 | LAST_NONCALLABLE_SPEC_OBJECT_TYPE = JS_REGEXP_TYPE, |
| 597 | // Boundaries for testing the types for which typeof is "function". |
| 598 | FIRST_CALLABLE_SPEC_OBJECT_TYPE = JS_FUNCTION_TYPE, |
| 599 | LAST_CALLABLE_SPEC_OBJECT_TYPE = JS_FUNCTION_PROXY_TYPE, |
| 600 | // Boundaries for testing whether the type is a JavaScript object. |
| 601 | FIRST_SPEC_OBJECT_TYPE = FIRST_NONCALLABLE_SPEC_OBJECT_TYPE, |
| 602 | LAST_SPEC_OBJECT_TYPE = LAST_CALLABLE_SPEC_OBJECT_TYPE |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 603 | }; |
| 604 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 605 | static const int kExternalArrayTypeCount = LAST_EXTERNAL_ARRAY_TYPE - |
| 606 | FIRST_EXTERNAL_ARRAY_TYPE + 1; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 607 | |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 608 | STATIC_CHECK(JS_OBJECT_TYPE == Internals::kJSObjectType); |
| 609 | STATIC_CHECK(FIRST_NONSTRING_TYPE == Internals::kFirstNonstringType); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 610 | STATIC_CHECK(FOREIGN_TYPE == Internals::kForeignType); |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 611 | |
| 612 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 613 | enum CompareResult { |
| 614 | LESS = -1, |
| 615 | EQUAL = 0, |
| 616 | GREATER = 1, |
| 617 | |
| 618 | NOT_EQUAL = GREATER |
| 619 | }; |
| 620 | |
| 621 | |
| 622 | #define DECL_BOOLEAN_ACCESSORS(name) \ |
| 623 | inline bool name(); \ |
| 624 | inline void set_##name(bool value); \ |
| 625 | |
| 626 | |
| 627 | #define DECL_ACCESSORS(name, type) \ |
| 628 | inline type* name(); \ |
| 629 | inline void set_##name(type* value, \ |
| 630 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); \ |
| 631 | |
| 632 | |
| 633 | class StringStream; |
| 634 | class ObjectVisitor; |
| 635 | |
| 636 | struct ValueInfo : public Malloced { |
| 637 | ValueInfo() : type(FIRST_TYPE), ptr(NULL), str(NULL), number(0) { } |
| 638 | InstanceType type; |
| 639 | Object* ptr; |
| 640 | const char* str; |
| 641 | double number; |
| 642 | }; |
| 643 | |
| 644 | |
| 645 | // A template-ized version of the IsXXX functions. |
| 646 | template <class C> static inline bool Is(Object* obj); |
| 647 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 648 | class Failure; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 649 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 650 | class MaybeObject BASE_EMBEDDED { |
| 651 | public: |
| 652 | inline bool IsFailure(); |
| 653 | inline bool IsRetryAfterGC(); |
| 654 | inline bool IsOutOfMemory(); |
| 655 | inline bool IsException(); |
| 656 | INLINE(bool IsTheHole()); |
| 657 | inline bool ToObject(Object** obj) { |
| 658 | if (IsFailure()) return false; |
| 659 | *obj = reinterpret_cast<Object*>(this); |
| 660 | return true; |
| 661 | } |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 662 | inline Failure* ToFailureUnchecked() { |
| 663 | ASSERT(IsFailure()); |
| 664 | return reinterpret_cast<Failure*>(this); |
| 665 | } |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 666 | inline Object* ToObjectUnchecked() { |
| 667 | ASSERT(!IsFailure()); |
| 668 | return reinterpret_cast<Object*>(this); |
| 669 | } |
| 670 | inline Object* ToObjectChecked() { |
| 671 | CHECK(!IsFailure()); |
| 672 | return reinterpret_cast<Object*>(this); |
| 673 | } |
| 674 | |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 675 | template<typename T> |
| 676 | inline bool To(T** obj) { |
| 677 | if (IsFailure()) return false; |
| 678 | *obj = T::cast(reinterpret_cast<Object*>(this)); |
| 679 | return true; |
| 680 | } |
| 681 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 682 | #ifdef OBJECT_PRINT |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 683 | // Prints this object with details. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 684 | inline void Print() { |
| 685 | Print(stdout); |
| 686 | }; |
| 687 | inline void PrintLn() { |
| 688 | PrintLn(stdout); |
| 689 | } |
| 690 | void Print(FILE* out); |
| 691 | void PrintLn(FILE* out); |
| 692 | #endif |
| 693 | #ifdef DEBUG |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 694 | // Verifies the object. |
| 695 | void Verify(); |
| 696 | #endif |
| 697 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 698 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 699 | |
| 700 | #define OBJECT_TYPE_LIST(V) \ |
| 701 | V(Smi) \ |
| 702 | V(HeapObject) \ |
| 703 | V(Number) \ |
| 704 | |
| 705 | #define HEAP_OBJECT_TYPE_LIST(V) \ |
| 706 | V(HeapNumber) \ |
| 707 | V(String) \ |
| 708 | V(Symbol) \ |
| 709 | V(SeqString) \ |
| 710 | V(ExternalString) \ |
| 711 | V(ConsString) \ |
| 712 | V(ExternalTwoByteString) \ |
| 713 | V(ExternalAsciiString) \ |
| 714 | V(SeqTwoByteString) \ |
| 715 | V(SeqAsciiString) \ |
| 716 | \ |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 717 | V(ExternalArray) \ |
| 718 | V(ExternalByteArray) \ |
| 719 | V(ExternalUnsignedByteArray) \ |
| 720 | V(ExternalShortArray) \ |
| 721 | V(ExternalUnsignedShortArray) \ |
| 722 | V(ExternalIntArray) \ |
| 723 | V(ExternalUnsignedIntArray) \ |
| 724 | V(ExternalFloatArray) \ |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 725 | V(ExternalDoubleArray) \ |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 726 | V(ExternalPixelArray) \ |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 727 | V(ByteArray) \ |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 728 | V(JSReceiver) \ |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 729 | V(JSObject) \ |
| 730 | V(JSContextExtensionObject) \ |
| 731 | V(Map) \ |
| 732 | V(DescriptorArray) \ |
| 733 | V(DeoptimizationInputData) \ |
| 734 | V(DeoptimizationOutputData) \ |
| 735 | V(FixedArray) \ |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 736 | V(FixedDoubleArray) \ |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 737 | V(Context) \ |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 738 | V(GlobalContext) \ |
| 739 | V(JSFunction) \ |
| 740 | V(Code) \ |
| 741 | V(Oddball) \ |
| 742 | V(SharedFunctionInfo) \ |
| 743 | V(JSValue) \ |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 744 | V(JSMessageObject) \ |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 745 | V(StringWrapper) \ |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 746 | V(Foreign) \ |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 747 | V(Boolean) \ |
| 748 | V(JSArray) \ |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 749 | V(JSProxy) \ |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 750 | V(JSFunctionProxy) \ |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 751 | V(JSRegExp) \ |
| 752 | V(HashTable) \ |
| 753 | V(Dictionary) \ |
| 754 | V(SymbolTable) \ |
| 755 | V(JSFunctionResultCache) \ |
| 756 | V(NormalizedMapCache) \ |
| 757 | V(CompilationCacheTable) \ |
| 758 | V(CodeCacheHashTable) \ |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 759 | V(PolymorphicCodeCacheHashTable) \ |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 760 | V(MapCache) \ |
| 761 | V(Primitive) \ |
| 762 | V(GlobalObject) \ |
| 763 | V(JSGlobalObject) \ |
| 764 | V(JSBuiltinsObject) \ |
| 765 | V(JSGlobalProxy) \ |
| 766 | V(UndetectableObject) \ |
| 767 | V(AccessCheckNeeded) \ |
| 768 | V(JSGlobalPropertyCell) \ |
| 769 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 770 | // Object is the abstract superclass for all classes in the |
| 771 | // object hierarchy. |
| 772 | // Object does not use any virtual functions to avoid the |
| 773 | // allocation of the C++ vtable. |
| 774 | // Since Smi and Failure are subclasses of Object no |
| 775 | // data members can be present in Object. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 776 | class Object : public MaybeObject { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 777 | public: |
| 778 | // Type testing. |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 779 | #define IS_TYPE_FUNCTION_DECL(type_) inline bool Is##type_(); |
| 780 | OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL) |
| 781 | HEAP_OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL) |
| 782 | #undef IS_TYPE_FUNCTION_DECL |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 783 | |
| 784 | // Returns true if this object is an instance of the specified |
| 785 | // function template. |
| 786 | inline bool IsInstanceOf(FunctionTemplateInfo* type); |
| 787 | |
| 788 | inline bool IsStruct(); |
| 789 | #define DECLARE_STRUCT_PREDICATE(NAME, Name, name) inline bool Is##Name(); |
| 790 | STRUCT_LIST(DECLARE_STRUCT_PREDICATE) |
| 791 | #undef DECLARE_STRUCT_PREDICATE |
| 792 | |
| 793 | // Oddball testing. |
| 794 | INLINE(bool IsUndefined()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 795 | INLINE(bool IsNull()); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 796 | INLINE(bool IsTheHole()); // Shadows MaybeObject's implementation. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 797 | INLINE(bool IsTrue()); |
| 798 | INLINE(bool IsFalse()); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 799 | inline bool IsArgumentsMarker(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 800 | |
| 801 | // Extract the number. |
| 802 | inline double Number(); |
| 803 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 804 | // Returns true if the object is of the correct type to be used as a |
| 805 | // implementation of a JSObject's elements. |
| 806 | inline bool HasValidElements(); |
| 807 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 808 | inline bool HasSpecificClassOf(String* name); |
| 809 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 810 | MUST_USE_RESULT MaybeObject* ToObject(); // ECMA-262 9.9. |
| 811 | Object* ToBoolean(); // ECMA-262 9.2. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 812 | |
| 813 | // Convert to a JSObject if needed. |
| 814 | // global_context is used when creating wrapper object. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 815 | MUST_USE_RESULT MaybeObject* ToObject(Context* global_context); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 816 | |
| 817 | // Converts this to a Smi if possible. |
| 818 | // Failure is returned otherwise. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 819 | MUST_USE_RESULT inline MaybeObject* ToSmi(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 820 | |
| 821 | void Lookup(String* name, LookupResult* result); |
| 822 | |
| 823 | // Property access. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 824 | MUST_USE_RESULT inline MaybeObject* GetProperty(String* key); |
| 825 | MUST_USE_RESULT inline MaybeObject* GetProperty( |
| 826 | String* key, |
| 827 | PropertyAttributes* attributes); |
| 828 | MUST_USE_RESULT MaybeObject* GetPropertyWithReceiver( |
| 829 | Object* receiver, |
| 830 | String* key, |
| 831 | PropertyAttributes* attributes); |
| 832 | MUST_USE_RESULT MaybeObject* GetProperty(Object* receiver, |
| 833 | LookupResult* result, |
| 834 | String* key, |
| 835 | PropertyAttributes* attributes); |
| 836 | MUST_USE_RESULT MaybeObject* GetPropertyWithCallback(Object* receiver, |
| 837 | Object* structure, |
| 838 | String* name, |
| 839 | Object* holder); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 840 | MUST_USE_RESULT MaybeObject* GetPropertyWithHandler(Object* receiver, |
| 841 | String* name, |
| 842 | Object* handler); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 843 | MUST_USE_RESULT MaybeObject* GetPropertyWithDefinedGetter(Object* receiver, |
| 844 | JSFunction* getter); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 845 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 846 | inline MaybeObject* GetElement(uint32_t index); |
| 847 | // For use when we know that no exception can be thrown. |
| 848 | inline Object* GetElementNoExceptionThrown(uint32_t index); |
| 849 | MaybeObject* GetElementWithReceiver(Object* receiver, uint32_t index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 850 | |
| 851 | // Return the object's prototype (might be Heap::null_value()). |
| 852 | Object* GetPrototype(); |
| 853 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 854 | // Tries to convert an object to an array index. Returns true and sets |
| 855 | // the output parameter if it succeeds. |
| 856 | inline bool ToArrayIndex(uint32_t* index); |
| 857 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 858 | // Returns true if this is a JSValue containing a string and the index is |
| 859 | // < the length of the string. Used to implement [] on strings. |
| 860 | inline bool IsStringObjectWithCharacterAt(uint32_t index); |
| 861 | |
| 862 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 863 | // Verify a pointer is a valid object pointer. |
| 864 | static void VerifyPointer(Object* p); |
| 865 | #endif |
| 866 | |
| 867 | // Prints this object without details. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 868 | inline void ShortPrint() { |
| 869 | ShortPrint(stdout); |
| 870 | } |
| 871 | void ShortPrint(FILE* out); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 872 | |
| 873 | // Prints this object without details to a message accumulator. |
| 874 | void ShortPrint(StringStream* accumulator); |
| 875 | |
| 876 | // Casting: This cast is only needed to satisfy macros in objects-inl.h. |
| 877 | static Object* cast(Object* value) { return value; } |
| 878 | |
| 879 | // Layout description. |
| 880 | static const int kHeaderSize = 0; // Object does not take up any space. |
| 881 | |
| 882 | private: |
| 883 | DISALLOW_IMPLICIT_CONSTRUCTORS(Object); |
| 884 | }; |
| 885 | |
| 886 | |
| 887 | // Smi represents integer Numbers that can be stored in 31 bits. |
| 888 | // Smis are immediate which means they are NOT allocated in the heap. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 889 | // The this pointer has the following format: [31 bit signed int] 0 |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 890 | // For long smis it has the following format: |
| 891 | // [32 bit signed int] [31 bits zero padding] 0 |
| 892 | // Smi stands for small integer. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 893 | class Smi: public Object { |
| 894 | public: |
| 895 | // Returns the integer value. |
| 896 | inline int value(); |
| 897 | |
| 898 | // Convert a value to a Smi object. |
| 899 | static inline Smi* FromInt(int value); |
| 900 | |
| 901 | static inline Smi* FromIntptr(intptr_t value); |
| 902 | |
| 903 | // Returns whether value can be represented in a Smi. |
| 904 | static inline bool IsValid(intptr_t value); |
| 905 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 906 | // Casting. |
| 907 | static inline Smi* cast(Object* object); |
| 908 | |
| 909 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 910 | inline void SmiPrint() { |
| 911 | SmiPrint(stdout); |
| 912 | } |
| 913 | void SmiPrint(FILE* out); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 914 | void SmiPrint(StringStream* accumulator); |
| 915 | #ifdef DEBUG |
| 916 | void SmiVerify(); |
| 917 | #endif |
| 918 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 919 | static const int kMinValue = (-1 << (kSmiValueSize - 1)); |
| 920 | static const int kMaxValue = -(kMinValue + 1); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 921 | |
| 922 | private: |
| 923 | DISALLOW_IMPLICIT_CONSTRUCTORS(Smi); |
| 924 | }; |
| 925 | |
| 926 | |
| 927 | // Failure is used for reporting out of memory situations and |
| 928 | // propagating exceptions through the runtime system. Failure objects |
| 929 | // are transient and cannot occur as part of the object graph. |
| 930 | // |
| 931 | // Failures are a single word, encoded as follows: |
| 932 | // +-------------------------+---+--+--+ |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 933 | // |.........unused..........|sss|tt|11| |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 934 | // +-------------------------+---+--+--+ |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 935 | // 7 6 4 32 10 |
| 936 | // |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 937 | // |
| 938 | // The low two bits, 0-1, are the failure tag, 11. The next two bits, |
| 939 | // 2-3, are a failure type tag 'tt' with possible values: |
| 940 | // 00 RETRY_AFTER_GC |
| 941 | // 01 EXCEPTION |
| 942 | // 10 INTERNAL_ERROR |
| 943 | // 11 OUT_OF_MEMORY_EXCEPTION |
| 944 | // |
| 945 | // The next three bits, 4-6, are an allocation space tag 'sss'. The |
| 946 | // allocation space tag is 000 for all failure types except |
| 947 | // RETRY_AFTER_GC. For RETRY_AFTER_GC, the possible values are the |
| 948 | // allocation spaces (the encoding is found in globals.h). |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 949 | |
| 950 | // Failure type tag info. |
| 951 | const int kFailureTypeTagSize = 2; |
| 952 | const int kFailureTypeTagMask = (1 << kFailureTypeTagSize) - 1; |
| 953 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 954 | class Failure: public MaybeObject { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 955 | public: |
| 956 | // RuntimeStubs assumes EXCEPTION = 1 in the compiler-generated code. |
| 957 | enum Type { |
| 958 | RETRY_AFTER_GC = 0, |
| 959 | EXCEPTION = 1, // Returning this marker tells the real exception |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 960 | // is in Isolate::pending_exception. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 961 | INTERNAL_ERROR = 2, |
| 962 | OUT_OF_MEMORY_EXCEPTION = 3 |
| 963 | }; |
| 964 | |
| 965 | inline Type type() const; |
| 966 | |
| 967 | // Returns the space that needs to be collected for RetryAfterGC failures. |
| 968 | inline AllocationSpace allocation_space() const; |
| 969 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 970 | inline bool IsInternalError() const; |
| 971 | inline bool IsOutOfMemoryException() const; |
| 972 | |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 973 | static inline Failure* RetryAfterGC(AllocationSpace space); |
| 974 | static inline Failure* RetryAfterGC(); // NEW_SPACE |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 975 | static inline Failure* Exception(); |
| 976 | static inline Failure* InternalError(); |
| 977 | static inline Failure* OutOfMemoryException(); |
| 978 | // Casting. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 979 | static inline Failure* cast(MaybeObject* object); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 980 | |
| 981 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 982 | inline void FailurePrint() { |
| 983 | FailurePrint(stdout); |
| 984 | } |
| 985 | void FailurePrint(FILE* out); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 986 | void FailurePrint(StringStream* accumulator); |
| 987 | #ifdef DEBUG |
| 988 | void FailureVerify(); |
| 989 | #endif |
| 990 | |
| 991 | private: |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 992 | inline intptr_t value() const; |
| 993 | static inline Failure* Construct(Type type, intptr_t value = 0); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 994 | |
| 995 | DISALLOW_IMPLICIT_CONSTRUCTORS(Failure); |
| 996 | }; |
| 997 | |
| 998 | |
| 999 | // Heap objects typically have a map pointer in their first word. However, |
| 1000 | // during GC other data (eg, mark bits, forwarding addresses) is sometimes |
| 1001 | // encoded in the first word. The class MapWord is an abstraction of the |
| 1002 | // value in a heap object's first word. |
| 1003 | class MapWord BASE_EMBEDDED { |
| 1004 | public: |
| 1005 | // Normal state: the map word contains a map pointer. |
| 1006 | |
| 1007 | // Create a map word from a map pointer. |
| 1008 | static inline MapWord FromMap(Map* map); |
| 1009 | |
| 1010 | // View this map word as a map pointer. |
| 1011 | inline Map* ToMap(); |
| 1012 | |
| 1013 | |
| 1014 | // Scavenge collection: the map word of live objects in the from space |
| 1015 | // contains a forwarding address (a heap object pointer in the to space). |
| 1016 | |
| 1017 | // True if this map word is a forwarding address for a scavenge |
| 1018 | // collection. Only valid during a scavenge collection (specifically, |
| 1019 | // when all map words are heap object pointers, ie. not during a full GC). |
| 1020 | inline bool IsForwardingAddress(); |
| 1021 | |
| 1022 | // Create a map word from a forwarding address. |
| 1023 | static inline MapWord FromForwardingAddress(HeapObject* object); |
| 1024 | |
| 1025 | // View this map word as a forwarding address. |
| 1026 | inline HeapObject* ToForwardingAddress(); |
| 1027 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1028 | // Marking phase of full collection: the map word of live objects is |
| 1029 | // marked, and may be marked as overflowed (eg, the object is live, its |
| 1030 | // children have not been visited, and it does not fit in the marking |
| 1031 | // stack). |
| 1032 | |
| 1033 | // True if this map word's mark bit is set. |
| 1034 | inline bool IsMarked(); |
| 1035 | |
| 1036 | // Return this map word but with its mark bit set. |
| 1037 | inline void SetMark(); |
| 1038 | |
| 1039 | // Return this map word but with its mark bit cleared. |
| 1040 | inline void ClearMark(); |
| 1041 | |
| 1042 | // True if this map word's overflow bit is set. |
| 1043 | inline bool IsOverflowed(); |
| 1044 | |
| 1045 | // Return this map word but with its overflow bit set. |
| 1046 | inline void SetOverflow(); |
| 1047 | |
| 1048 | // Return this map word but with its overflow bit cleared. |
| 1049 | inline void ClearOverflow(); |
| 1050 | |
| 1051 | |
| 1052 | // Compacting phase of a full compacting collection: the map word of live |
| 1053 | // objects contains an encoding of the original map address along with the |
| 1054 | // forwarding address (represented as an offset from the first live object |
| 1055 | // in the same page as the (old) object address). |
| 1056 | |
| 1057 | // Create a map word from a map address and a forwarding address offset. |
| 1058 | static inline MapWord EncodeAddress(Address map_address, int offset); |
| 1059 | |
| 1060 | // Return the map address encoded in this map word. |
| 1061 | inline Address DecodeMapAddress(MapSpace* map_space); |
| 1062 | |
| 1063 | // Return the forwarding offset encoded in this map word. |
| 1064 | inline int DecodeOffset(); |
| 1065 | |
| 1066 | |
| 1067 | // During serialization: the map word is used to hold an encoded |
| 1068 | // address, and possibly a mark bit (set and cleared with SetMark |
| 1069 | // and ClearMark). |
| 1070 | |
| 1071 | // Create a map word from an encoded address. |
| 1072 | static inline MapWord FromEncodedAddress(Address address); |
| 1073 | |
| 1074 | inline Address ToEncodedAddress(); |
| 1075 | |
| 1076 | // Bits used by the marking phase of the garbage collector. |
| 1077 | // |
| 1078 | // The first word of a heap object is normally a map pointer. The last two |
| 1079 | // bits are tagged as '01' (kHeapObjectTag). We reuse the last two bits to |
| 1080 | // mark an object as live and/or overflowed: |
| 1081 | // last bit = 0, marked as alive |
| 1082 | // second bit = 1, overflowed |
| 1083 | // An object is only marked as overflowed when it is marked as live while |
| 1084 | // the marking stack is overflowed. |
| 1085 | static const int kMarkingBit = 0; // marking bit |
| 1086 | static const int kMarkingMask = (1 << kMarkingBit); // marking mask |
| 1087 | static const int kOverflowBit = 1; // overflow bit |
| 1088 | static const int kOverflowMask = (1 << kOverflowBit); // overflow mask |
| 1089 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1090 | // Forwarding pointers and map pointer encoding. On 32 bit all the bits are |
| 1091 | // used. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1092 | // +-----------------+------------------+-----------------+ |
| 1093 | // |forwarding offset|page offset of map|page index of map| |
| 1094 | // +-----------------+------------------+-----------------+ |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1095 | // ^ ^ ^ |
| 1096 | // | | | |
| 1097 | // | | kMapPageIndexBits |
| 1098 | // | kMapPageOffsetBits |
| 1099 | // kForwardingOffsetBits |
| 1100 | static const int kMapPageOffsetBits = kPageSizeBits - kMapAlignmentBits; |
| 1101 | static const int kForwardingOffsetBits = kPageSizeBits - kObjectAlignmentBits; |
| 1102 | #ifdef V8_HOST_ARCH_64_BIT |
| 1103 | static const int kMapPageIndexBits = 16; |
| 1104 | #else |
| 1105 | // Use all the 32-bits to encode on a 32-bit platform. |
| 1106 | static const int kMapPageIndexBits = |
| 1107 | 32 - (kMapPageOffsetBits + kForwardingOffsetBits); |
| 1108 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1109 | |
| 1110 | static const int kMapPageIndexShift = 0; |
| 1111 | static const int kMapPageOffsetShift = |
| 1112 | kMapPageIndexShift + kMapPageIndexBits; |
| 1113 | static const int kForwardingOffsetShift = |
| 1114 | kMapPageOffsetShift + kMapPageOffsetBits; |
| 1115 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1116 | // Bit masks covering the different parts the encoding. |
| 1117 | static const uintptr_t kMapPageIndexMask = |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1118 | (1 << kMapPageOffsetShift) - 1; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1119 | static const uintptr_t kMapPageOffsetMask = |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1120 | ((1 << kForwardingOffsetShift) - 1) & ~kMapPageIndexMask; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1121 | static const uintptr_t kForwardingOffsetMask = |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1122 | ~(kMapPageIndexMask | kMapPageOffsetMask); |
| 1123 | |
| 1124 | private: |
| 1125 | // HeapObject calls the private constructor and directly reads the value. |
| 1126 | friend class HeapObject; |
| 1127 | |
| 1128 | explicit MapWord(uintptr_t value) : value_(value) {} |
| 1129 | |
| 1130 | uintptr_t value_; |
| 1131 | }; |
| 1132 | |
| 1133 | |
| 1134 | // HeapObject is the superclass for all classes describing heap allocated |
| 1135 | // objects. |
| 1136 | class HeapObject: public Object { |
| 1137 | public: |
| 1138 | // [map]: Contains a map which contains the object's reflective |
| 1139 | // information. |
| 1140 | inline Map* map(); |
| 1141 | inline void set_map(Map* value); |
| 1142 | |
| 1143 | // During garbage collection, the map word of a heap object does not |
| 1144 | // necessarily contain a map pointer. |
| 1145 | inline MapWord map_word(); |
| 1146 | inline void set_map_word(MapWord map_word); |
| 1147 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1148 | // The Heap the object was allocated in. Used also to access Isolate. |
| 1149 | // This method can not be used during GC, it ASSERTs this. |
| 1150 | inline Heap* GetHeap(); |
| 1151 | // Convenience method to get current isolate. This method can be |
| 1152 | // accessed only when its result is the same as |
| 1153 | // Isolate::Current(), it ASSERTs this. See also comment for GetHeap. |
| 1154 | inline Isolate* GetIsolate(); |
| 1155 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1156 | // Converts an address to a HeapObject pointer. |
| 1157 | static inline HeapObject* FromAddress(Address address); |
| 1158 | |
| 1159 | // Returns the address of this HeapObject. |
| 1160 | inline Address address(); |
| 1161 | |
| 1162 | // Iterates over pointers contained in the object (including the Map) |
| 1163 | void Iterate(ObjectVisitor* v); |
| 1164 | |
| 1165 | // Iterates over all pointers contained in the object except the |
| 1166 | // first map pointer. The object type is given in the first |
| 1167 | // parameter. This function does not access the map pointer in the |
| 1168 | // object, and so is safe to call while the map pointer is modified. |
| 1169 | void IterateBody(InstanceType type, int object_size, ObjectVisitor* v); |
| 1170 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1171 | // Returns the heap object's size in bytes |
| 1172 | inline int Size(); |
| 1173 | |
| 1174 | // Given a heap object's map pointer, returns the heap size in bytes |
| 1175 | // Useful when the map pointer field is used for other purposes. |
| 1176 | // GC internal. |
| 1177 | inline int SizeFromMap(Map* map); |
| 1178 | |
| 1179 | // Support for the marking heap objects during the marking phase of GC. |
| 1180 | // True if the object is marked live. |
| 1181 | inline bool IsMarked(); |
| 1182 | |
| 1183 | // Mutate this object's map pointer to indicate that the object is live. |
| 1184 | inline void SetMark(); |
| 1185 | |
| 1186 | // Mutate this object's map pointer to remove the indication that the |
| 1187 | // object is live (ie, partially restore the map pointer). |
| 1188 | inline void ClearMark(); |
| 1189 | |
| 1190 | // True if this object is marked as overflowed. Overflowed objects have |
| 1191 | // been reached and marked during marking of the heap, but their children |
| 1192 | // have not necessarily been marked and they have not been pushed on the |
| 1193 | // marking stack. |
| 1194 | inline bool IsOverflowed(); |
| 1195 | |
| 1196 | // Mutate this object's map pointer to indicate that the object is |
| 1197 | // overflowed. |
| 1198 | inline void SetOverflow(); |
| 1199 | |
| 1200 | // Mutate this object's map pointer to remove the indication that the |
| 1201 | // object is overflowed (ie, partially restore the map pointer). |
| 1202 | inline void ClearOverflow(); |
| 1203 | |
| 1204 | // Returns the field at offset in obj, as a read/write Object* reference. |
| 1205 | // 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] | 1206 | // Does not invoke write barrier, so should only be assigned to |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1207 | // during marking GC. |
| 1208 | static inline Object** RawField(HeapObject* obj, int offset); |
| 1209 | |
| 1210 | // Casting. |
| 1211 | static inline HeapObject* cast(Object* obj); |
| 1212 | |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 1213 | // Return the write barrier mode for this. Callers of this function |
| 1214 | // must be able to present a reference to an AssertNoAllocation |
| 1215 | // object as a sign that they are not going to use this function |
| 1216 | // from code that allocates and thus invalidates the returned write |
| 1217 | // barrier mode. |
| 1218 | inline WriteBarrierMode GetWriteBarrierMode(const AssertNoAllocation&); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1219 | |
| 1220 | // Dispatched behavior. |
| 1221 | void HeapObjectShortPrint(StringStream* accumulator); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1222 | #ifdef OBJECT_PRINT |
| 1223 | inline void HeapObjectPrint() { |
| 1224 | HeapObjectPrint(stdout); |
| 1225 | } |
| 1226 | void HeapObjectPrint(FILE* out); |
| 1227 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1228 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1229 | void HeapObjectVerify(); |
| 1230 | inline void VerifyObjectField(int offset); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1231 | inline void VerifySmiField(int offset); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1232 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1233 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1234 | #ifdef OBJECT_PRINT |
| 1235 | void PrintHeader(FILE* out, const char* id); |
| 1236 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1237 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1238 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1239 | // Verify a pointer is a valid HeapObject pointer that points to object |
| 1240 | // areas in the heap. |
| 1241 | static void VerifyHeapPointer(Object* p); |
| 1242 | #endif |
| 1243 | |
| 1244 | // Layout description. |
| 1245 | // First field in a heap object is map. |
| 1246 | static const int kMapOffset = Object::kHeaderSize; |
| 1247 | static const int kHeaderSize = kMapOffset + kPointerSize; |
| 1248 | |
| 1249 | STATIC_CHECK(kMapOffset == Internals::kHeapObjectMapOffset); |
| 1250 | |
| 1251 | protected: |
| 1252 | // helpers for calling an ObjectVisitor to iterate over pointers in the |
| 1253 | // half-open range [start, end) specified as integer offsets |
| 1254 | inline void IteratePointers(ObjectVisitor* v, int start, int end); |
| 1255 | // as above, for the single element at "offset" |
| 1256 | inline void IteratePointer(ObjectVisitor* v, int offset); |
| 1257 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1258 | private: |
| 1259 | DISALLOW_IMPLICIT_CONSTRUCTORS(HeapObject); |
| 1260 | }; |
| 1261 | |
| 1262 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1263 | #define SLOT_ADDR(obj, offset) \ |
| 1264 | reinterpret_cast<Object**>((obj)->address() + offset) |
| 1265 | |
| 1266 | // This class describes a body of an object of a fixed size |
| 1267 | // in which all pointer fields are located in the [start_offset, end_offset) |
| 1268 | // interval. |
| 1269 | template<int start_offset, int end_offset, int size> |
| 1270 | class FixedBodyDescriptor { |
| 1271 | public: |
| 1272 | static const int kStartOffset = start_offset; |
| 1273 | static const int kEndOffset = end_offset; |
| 1274 | static const int kSize = size; |
| 1275 | |
| 1276 | static inline void IterateBody(HeapObject* obj, ObjectVisitor* v); |
| 1277 | |
| 1278 | template<typename StaticVisitor> |
| 1279 | static inline void IterateBody(HeapObject* obj) { |
| 1280 | StaticVisitor::VisitPointers(SLOT_ADDR(obj, start_offset), |
| 1281 | SLOT_ADDR(obj, end_offset)); |
| 1282 | } |
| 1283 | }; |
| 1284 | |
| 1285 | |
| 1286 | // This class describes a body of an object of a variable size |
| 1287 | // in which all pointer fields are located in the [start_offset, object_size) |
| 1288 | // interval. |
| 1289 | template<int start_offset> |
| 1290 | class FlexibleBodyDescriptor { |
| 1291 | public: |
| 1292 | static const int kStartOffset = start_offset; |
| 1293 | |
| 1294 | static inline void IterateBody(HeapObject* obj, |
| 1295 | int object_size, |
| 1296 | ObjectVisitor* v); |
| 1297 | |
| 1298 | template<typename StaticVisitor> |
| 1299 | static inline void IterateBody(HeapObject* obj, int object_size) { |
| 1300 | StaticVisitor::VisitPointers(SLOT_ADDR(obj, start_offset), |
| 1301 | SLOT_ADDR(obj, object_size)); |
| 1302 | } |
| 1303 | }; |
| 1304 | |
| 1305 | #undef SLOT_ADDR |
| 1306 | |
| 1307 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1308 | // The HeapNumber class describes heap allocated numbers that cannot be |
| 1309 | // represented in a Smi (small integer) |
| 1310 | class HeapNumber: public HeapObject { |
| 1311 | public: |
| 1312 | // [value]: number value. |
| 1313 | inline double value(); |
| 1314 | inline void set_value(double value); |
| 1315 | |
| 1316 | // Casting. |
| 1317 | static inline HeapNumber* cast(Object* obj); |
| 1318 | |
| 1319 | // Dispatched behavior. |
| 1320 | Object* HeapNumberToBoolean(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1321 | inline void HeapNumberPrint() { |
| 1322 | HeapNumberPrint(stdout); |
| 1323 | } |
| 1324 | void HeapNumberPrint(FILE* out); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1325 | void HeapNumberPrint(StringStream* accumulator); |
| 1326 | #ifdef DEBUG |
| 1327 | void HeapNumberVerify(); |
| 1328 | #endif |
| 1329 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1330 | inline int get_exponent(); |
| 1331 | inline int get_sign(); |
| 1332 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1333 | // Layout description. |
| 1334 | static const int kValueOffset = HeapObject::kHeaderSize; |
| 1335 | // IEEE doubles are two 32 bit words. The first is just mantissa, the second |
| 1336 | // is a mixture of sign, exponent and mantissa. Our current platforms are all |
| 1337 | // little endian apart from non-EABI arm which is little endian with big |
| 1338 | // endian floating point word ordering! |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1339 | static const int kMantissaOffset = kValueOffset; |
| 1340 | static const int kExponentOffset = kValueOffset + 4; |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1341 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1342 | static const int kSize = kValueOffset + kDoubleSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1343 | static const uint32_t kSignMask = 0x80000000u; |
| 1344 | static const uint32_t kExponentMask = 0x7ff00000u; |
| 1345 | static const uint32_t kMantissaMask = 0xfffffu; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1346 | static const int kMantissaBits = 52; |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 1347 | static const int kExponentBits = 11; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1348 | static const int kExponentBias = 1023; |
| 1349 | static const int kExponentShift = 20; |
| 1350 | static const int kMantissaBitsInTopWord = 20; |
| 1351 | static const int kNonMantissaBitsInTopWord = 12; |
| 1352 | |
| 1353 | private: |
| 1354 | DISALLOW_IMPLICIT_CONSTRUCTORS(HeapNumber); |
| 1355 | }; |
| 1356 | |
| 1357 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 1358 | // JSReceiver includes types on which properties can be defined, i.e., |
| 1359 | // JSObject and JSProxy. |
| 1360 | class JSReceiver: public HeapObject { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1361 | public: |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1362 | enum DeleteMode { |
| 1363 | NORMAL_DELETION, |
| 1364 | STRICT_DELETION, |
| 1365 | FORCE_DELETION |
| 1366 | }; |
| 1367 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 1368 | // Casting. |
| 1369 | static inline JSReceiver* cast(Object* obj); |
| 1370 | |
| 1371 | // Can cause GC. |
| 1372 | MUST_USE_RESULT MaybeObject* SetProperty(String* key, |
| 1373 | Object* value, |
| 1374 | PropertyAttributes attributes, |
| 1375 | StrictModeFlag strict_mode); |
| 1376 | MUST_USE_RESULT MaybeObject* SetProperty(LookupResult* result, |
| 1377 | String* key, |
| 1378 | Object* value, |
| 1379 | PropertyAttributes attributes, |
| 1380 | StrictModeFlag strict_mode); |
| 1381 | |
| 1382 | MUST_USE_RESULT MaybeObject* DeleteProperty(String* name, DeleteMode mode); |
| 1383 | |
| 1384 | // Returns the class name ([[Class]] property in the specification). |
| 1385 | String* class_name(); |
| 1386 | |
| 1387 | // Returns the constructor name (the name (possibly, inferred name) of the |
| 1388 | // function that was used to instantiate the object). |
| 1389 | String* constructor_name(); |
| 1390 | |
| 1391 | inline PropertyAttributes GetPropertyAttribute(String* name); |
| 1392 | PropertyAttributes GetPropertyAttributeWithReceiver(JSReceiver* receiver, |
| 1393 | String* name); |
| 1394 | PropertyAttributes GetLocalPropertyAttribute(String* name); |
| 1395 | |
| 1396 | // Can cause a GC. |
| 1397 | inline bool HasProperty(String* name); |
| 1398 | inline bool HasLocalProperty(String* name); |
| 1399 | |
| 1400 | // Return the object's prototype (might be Heap::null_value()). |
| 1401 | inline Object* GetPrototype(); |
| 1402 | |
| 1403 | // Set the object's prototype (only JSReceiver and null are allowed). |
| 1404 | MUST_USE_RESULT MaybeObject* SetPrototype(Object* value, |
| 1405 | bool skip_hidden_prototypes); |
| 1406 | |
| 1407 | // Lookup a property. If found, the result is valid and has |
| 1408 | // detailed information. |
| 1409 | void LocalLookup(String* name, LookupResult* result); |
| 1410 | void Lookup(String* name, LookupResult* result); |
| 1411 | |
| 1412 | private: |
| 1413 | PropertyAttributes GetPropertyAttribute(JSReceiver* receiver, |
| 1414 | LookupResult* result, |
| 1415 | String* name, |
| 1416 | bool continue_search); |
| 1417 | |
| 1418 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSReceiver); |
| 1419 | }; |
| 1420 | |
| 1421 | // The JSObject describes real heap allocated JavaScript objects with |
| 1422 | // properties. |
| 1423 | // Note that the map of JSObject changes during execution to enable inline |
| 1424 | // caching. |
| 1425 | class JSObject: public JSReceiver { |
| 1426 | public: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1427 | enum ElementsKind { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 1428 | // The "fast" kind for tagged values. Must be first to make it possible |
| 1429 | // to efficiently check maps if they have fast elements. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1430 | FAST_ELEMENTS, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 1431 | |
| 1432 | // The "fast" kind for unwrapped, non-tagged double values. |
| 1433 | FAST_DOUBLE_ELEMENTS, |
| 1434 | |
| 1435 | // The "slow" kind. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1436 | DICTIONARY_ELEMENTS, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 1437 | NON_STRICT_ARGUMENTS_ELEMENTS, |
| 1438 | // The "fast" kind for external arrays |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1439 | EXTERNAL_BYTE_ELEMENTS, |
| 1440 | EXTERNAL_UNSIGNED_BYTE_ELEMENTS, |
| 1441 | EXTERNAL_SHORT_ELEMENTS, |
| 1442 | EXTERNAL_UNSIGNED_SHORT_ELEMENTS, |
| 1443 | EXTERNAL_INT_ELEMENTS, |
| 1444 | EXTERNAL_UNSIGNED_INT_ELEMENTS, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1445 | EXTERNAL_FLOAT_ELEMENTS, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1446 | EXTERNAL_DOUBLE_ELEMENTS, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 1447 | EXTERNAL_PIXEL_ELEMENTS, |
| 1448 | |
| 1449 | // Derived constants from ElementsKind |
| 1450 | FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND = EXTERNAL_BYTE_ELEMENTS, |
| 1451 | LAST_EXTERNAL_ARRAY_ELEMENTS_KIND = EXTERNAL_PIXEL_ELEMENTS, |
| 1452 | FIRST_ELEMENTS_KIND = FAST_ELEMENTS, |
| 1453 | LAST_ELEMENTS_KIND = EXTERNAL_PIXEL_ELEMENTS |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1454 | }; |
| 1455 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 1456 | static const int kElementsKindCount = |
| 1457 | LAST_ELEMENTS_KIND - FIRST_ELEMENTS_KIND + 1; |
| 1458 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1459 | // [properties]: Backing storage for properties. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1460 | // 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] | 1461 | // slow case. |
| 1462 | DECL_ACCESSORS(properties, FixedArray) // Get and set fast properties. |
| 1463 | inline void initialize_properties(); |
| 1464 | inline bool HasFastProperties(); |
| 1465 | inline StringDictionary* property_dictionary(); // Gets slow properties. |
| 1466 | |
| 1467 | // [elements]: The elements (properties with names that are integers). |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1468 | // |
| 1469 | // Elements can be in two general modes: fast and slow. Each mode |
| 1470 | // corrensponds to a set of object representations of elements that |
| 1471 | // have something in common. |
| 1472 | // |
| 1473 | // In the fast mode elements is a FixedArray and so each element can |
| 1474 | // be quickly accessed. This fact is used in the generated code. The |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 1475 | // elements array can have one of three maps in this mode: |
| 1476 | // fixed_array_map, non_strict_arguments_elements_map or |
| 1477 | // fixed_cow_array_map (for copy-on-write arrays). In the latter case |
| 1478 | // the elements array may be shared by a few objects and so before |
| 1479 | // writing to any element the array must be copied. Use |
| 1480 | // EnsureWritableFastElements in this case. |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1481 | // |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 1482 | // In the slow mode the elements is either a NumberDictionary, an |
| 1483 | // ExternalArray, or a FixedArray parameter map for a (non-strict) |
| 1484 | // arguments object. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1485 | DECL_ACCESSORS(elements, HeapObject) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1486 | inline void initialize_elements(); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1487 | MUST_USE_RESULT inline MaybeObject* ResetElements(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1488 | inline ElementsKind GetElementsKind(); |
| 1489 | inline bool HasFastElements(); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 1490 | inline bool HasFastDoubleElements(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1491 | inline bool HasDictionaryElements(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1492 | inline bool HasExternalPixelElements(); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1493 | inline bool HasExternalArrayElements(); |
| 1494 | inline bool HasExternalByteElements(); |
| 1495 | inline bool HasExternalUnsignedByteElements(); |
| 1496 | inline bool HasExternalShortElements(); |
| 1497 | inline bool HasExternalUnsignedShortElements(); |
| 1498 | inline bool HasExternalIntElements(); |
| 1499 | inline bool HasExternalUnsignedIntElements(); |
| 1500 | inline bool HasExternalFloatElements(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1501 | inline bool HasExternalDoubleElements(); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 1502 | bool HasFastArgumentsElements(); |
| 1503 | bool HasDictionaryArgumentsElements(); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1504 | inline bool AllowsSetElementsLength(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1505 | inline NumberDictionary* element_dictionary(); // Gets slow elements. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 1506 | |
| 1507 | // Requires: HasFastElements(). |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1508 | MUST_USE_RESULT inline MaybeObject* EnsureWritableFastElements(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1509 | |
| 1510 | // Collects elements starting at index 0. |
| 1511 | // Undefined values are placed after non-undefined values. |
| 1512 | // Returns the number of non-undefined values. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1513 | MUST_USE_RESULT MaybeObject* PrepareElementsForSort(uint32_t limit); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1514 | // As PrepareElementsForSort, but only on objects where elements is |
| 1515 | // a dictionary, and it will stay a dictionary. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1516 | MUST_USE_RESULT MaybeObject* PrepareSlowElementsForSort(uint32_t limit); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1517 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 1518 | MUST_USE_RESULT MaybeObject* SetPropertyForResult(LookupResult* result, |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1519 | String* key, |
| 1520 | Object* value, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1521 | PropertyAttributes attributes, |
| 1522 | StrictModeFlag strict_mode); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1523 | MUST_USE_RESULT MaybeObject* SetPropertyWithFailedAccessCheck( |
| 1524 | LookupResult* result, |
| 1525 | String* name, |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 1526 | Object* value, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 1527 | bool check_prototype, |
| 1528 | StrictModeFlag strict_mode); |
| 1529 | MUST_USE_RESULT MaybeObject* SetPropertyWithCallback( |
| 1530 | Object* structure, |
| 1531 | String* name, |
| 1532 | Object* value, |
| 1533 | JSObject* holder, |
| 1534 | StrictModeFlag strict_mode); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1535 | MUST_USE_RESULT MaybeObject* SetPropertyWithDefinedSetter(JSFunction* setter, |
| 1536 | Object* value); |
| 1537 | MUST_USE_RESULT MaybeObject* SetPropertyWithInterceptor( |
| 1538 | String* name, |
| 1539 | Object* value, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1540 | PropertyAttributes attributes, |
| 1541 | StrictModeFlag strict_mode); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1542 | MUST_USE_RESULT MaybeObject* SetPropertyPostInterceptor( |
| 1543 | String* name, |
| 1544 | Object* value, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1545 | PropertyAttributes attributes, |
| 1546 | StrictModeFlag strict_mode); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 1547 | MUST_USE_RESULT MaybeObject* SetLocalPropertyIgnoreAttributes( |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1548 | String* key, |
| 1549 | Object* value, |
| 1550 | PropertyAttributes attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1551 | |
| 1552 | // Retrieve a value in a normalized object given a lookup result. |
| 1553 | // Handles the special representation of JS global objects. |
| 1554 | Object* GetNormalizedProperty(LookupResult* result); |
| 1555 | |
| 1556 | // Sets the property value in a normalized object given a lookup result. |
| 1557 | // Handles the special representation of JS global objects. |
| 1558 | Object* SetNormalizedProperty(LookupResult* result, Object* value); |
| 1559 | |
| 1560 | // Sets the property value in a normalized object given (key, value, details). |
| 1561 | // Handles the special representation of JS global objects. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1562 | MUST_USE_RESULT MaybeObject* SetNormalizedProperty(String* name, |
| 1563 | Object* value, |
| 1564 | PropertyDetails details); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1565 | |
| 1566 | // Deletes the named property in a normalized object. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1567 | MUST_USE_RESULT MaybeObject* DeleteNormalizedProperty(String* name, |
| 1568 | DeleteMode mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1569 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1570 | // Retrieve interceptors. |
| 1571 | InterceptorInfo* GetNamedInterceptor(); |
| 1572 | InterceptorInfo* GetIndexedInterceptor(); |
| 1573 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 1574 | // Used from JSReceiver. |
| 1575 | PropertyAttributes GetPropertyAttributePostInterceptor(JSObject* receiver, |
| 1576 | String* name, |
| 1577 | bool continue_search); |
| 1578 | PropertyAttributes GetPropertyAttributeWithInterceptor(JSObject* receiver, |
| 1579 | String* name, |
| 1580 | bool continue_search); |
| 1581 | PropertyAttributes GetPropertyAttributeWithFailedAccessCheck( |
| 1582 | Object* receiver, |
| 1583 | LookupResult* result, |
| 1584 | String* name, |
| 1585 | bool continue_search); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1586 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1587 | MUST_USE_RESULT MaybeObject* DefineAccessor(String* name, |
| 1588 | bool is_getter, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1589 | Object* fun, |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1590 | PropertyAttributes attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1591 | Object* LookupAccessor(String* name, bool is_getter); |
| 1592 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1593 | MUST_USE_RESULT MaybeObject* DefineAccessor(AccessorInfo* info); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1594 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1595 | // Used from Object::GetProperty(). |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1596 | MaybeObject* GetPropertyWithFailedAccessCheck( |
| 1597 | Object* receiver, |
| 1598 | LookupResult* result, |
| 1599 | String* name, |
| 1600 | PropertyAttributes* attributes); |
| 1601 | MaybeObject* GetPropertyWithInterceptor( |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 1602 | JSReceiver* receiver, |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1603 | String* name, |
| 1604 | PropertyAttributes* attributes); |
| 1605 | MaybeObject* GetPropertyPostInterceptor( |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 1606 | JSReceiver* receiver, |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1607 | String* name, |
| 1608 | PropertyAttributes* attributes); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 1609 | MaybeObject* GetLocalPropertyPostInterceptor(JSReceiver* receiver, |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1610 | String* name, |
| 1611 | PropertyAttributes* attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1612 | |
| 1613 | // Returns true if this is an instance of an api function and has |
| 1614 | // been modified since it was created. May give false positives. |
| 1615 | bool IsDirty(); |
| 1616 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1617 | // If the receiver is a JSGlobalProxy this method will return its prototype, |
| 1618 | // otherwise the result is the receiver itself. |
| 1619 | inline Object* BypassGlobalProxy(); |
| 1620 | |
| 1621 | // Accessors for hidden properties object. |
| 1622 | // |
| 1623 | // Hidden properties are not local properties of the object itself. |
| 1624 | // Instead they are stored on an auxiliary JSObject stored as a local |
| 1625 | // property with a special name Heap::hidden_symbol(). But if the |
| 1626 | // receiver is a JSGlobalProxy then the auxiliary object is a property |
| 1627 | // of its prototype. |
| 1628 | // |
| 1629 | // Has/Get/SetHiddenPropertiesObject methods don't allow the holder to be |
| 1630 | // a JSGlobalProxy. Use BypassGlobalProxy method above to get to the real |
| 1631 | // holder. |
| 1632 | // |
| 1633 | // These accessors do not touch interceptors or accessors. |
| 1634 | inline bool HasHiddenPropertiesObject(); |
| 1635 | inline Object* GetHiddenPropertiesObject(); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1636 | MUST_USE_RESULT inline MaybeObject* SetHiddenPropertiesObject( |
| 1637 | Object* hidden_obj); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1638 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1639 | MUST_USE_RESULT MaybeObject* DeleteProperty(String* name, DeleteMode mode); |
| 1640 | MUST_USE_RESULT MaybeObject* DeleteElement(uint32_t index, DeleteMode mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1641 | |
| 1642 | // Tests for the fast common case for property enumeration. |
| 1643 | bool IsSimpleEnum(); |
| 1644 | |
| 1645 | // Do we want to keep the elements in fast case when increasing the |
| 1646 | // capacity? |
| 1647 | bool ShouldConvertToSlowElements(int new_capacity); |
| 1648 | // Returns true if the backing storage for the slow-case elements of |
| 1649 | // this object takes up nearly as much space as a fast-case backing |
| 1650 | // storage would. In that case the JSObject should have fast |
| 1651 | // elements. |
| 1652 | bool ShouldConvertToFastElements(); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 1653 | // Returns true if the elements of JSObject contains only values that can be |
| 1654 | // represented in a FixedDoubleArray. |
| 1655 | bool ShouldConvertToFastDoubleElements(); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1656 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1657 | // Tells whether the index'th element is present. |
| 1658 | inline bool HasElement(uint32_t index); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 1659 | bool HasElementWithReceiver(JSReceiver* receiver, uint32_t index); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1660 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1661 | // Computes the new capacity when expanding the elements of a JSObject. |
| 1662 | static int NewElementsCapacity(int old_capacity) { |
| 1663 | // (old_capacity + 50%) + 16 |
| 1664 | return old_capacity + (old_capacity >> 1) + 16; |
| 1665 | } |
| 1666 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1667 | // Tells whether the index'th element is present and how it is stored. |
| 1668 | enum LocalElementType { |
| 1669 | // There is no element with given index. |
| 1670 | UNDEFINED_ELEMENT, |
| 1671 | |
| 1672 | // Element with given index is handled by interceptor. |
| 1673 | INTERCEPTED_ELEMENT, |
| 1674 | |
| 1675 | // Element with given index is character in string. |
| 1676 | STRING_CHARACTER_ELEMENT, |
| 1677 | |
| 1678 | // Element with given index is stored in fast backing store. |
| 1679 | FAST_ELEMENT, |
| 1680 | |
| 1681 | // Element with given index is stored in slow backing store. |
| 1682 | DICTIONARY_ELEMENT |
| 1683 | }; |
| 1684 | |
| 1685 | LocalElementType HasLocalElement(uint32_t index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1686 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 1687 | bool HasElementWithInterceptor(JSReceiver* receiver, uint32_t index); |
| 1688 | bool HasElementPostInterceptor(JSReceiver* receiver, uint32_t index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1689 | |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 1690 | MUST_USE_RESULT MaybeObject* SetFastElement(uint32_t index, |
| 1691 | Object* value, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1692 | StrictModeFlag strict_mode, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 1693 | bool check_prototype); |
| 1694 | MUST_USE_RESULT MaybeObject* SetDictionaryElement(uint32_t index, |
| 1695 | Object* value, |
| 1696 | StrictModeFlag strict_mode, |
| 1697 | bool check_prototype); |
| 1698 | |
| 1699 | MUST_USE_RESULT MaybeObject* SetFastDoubleElement( |
| 1700 | uint32_t index, |
| 1701 | Object* value, |
| 1702 | StrictModeFlag strict_mode, |
| 1703 | bool check_prototype = true); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1704 | |
| 1705 | // Set the index'th array element. |
| 1706 | // A Failure object is returned if GC is needed. |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 1707 | MUST_USE_RESULT MaybeObject* SetElement(uint32_t index, |
| 1708 | Object* value, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1709 | StrictModeFlag strict_mode, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 1710 | bool check_prototype); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1711 | |
| 1712 | // Returns the index'th element. |
| 1713 | // The undefined object if index is out of bounds. |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1714 | MaybeObject* GetElementWithReceiver(Object* receiver, uint32_t index); |
| 1715 | MaybeObject* GetElementWithInterceptor(Object* receiver, uint32_t index); |
| 1716 | |
| 1717 | // Get external element value at index if there is one and undefined |
| 1718 | // otherwise. Can return a failure if allocation of a heap number |
| 1719 | // failed. |
| 1720 | MaybeObject* GetExternalElement(uint32_t index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1721 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 1722 | // Replace the elements' backing store with fast elements of the given |
| 1723 | // capacity. Update the length for JSArrays. Returns the new backing |
| 1724 | // store. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1725 | MUST_USE_RESULT MaybeObject* SetFastElementsCapacityAndLength(int capacity, |
| 1726 | int length); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 1727 | MUST_USE_RESULT MaybeObject* SetFastDoubleElementsCapacityAndLength( |
| 1728 | int capacity, |
| 1729 | int length); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1730 | MUST_USE_RESULT MaybeObject* SetSlowElements(Object* length); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1731 | |
| 1732 | // Lookup interceptors are used for handling properties controlled by host |
| 1733 | // objects. |
| 1734 | inline bool HasNamedInterceptor(); |
| 1735 | inline bool HasIndexedInterceptor(); |
| 1736 | |
| 1737 | // Support functions for v8 api (needed for correct interceptor behavior). |
| 1738 | bool HasRealNamedProperty(String* key); |
| 1739 | bool HasRealElementProperty(uint32_t index); |
| 1740 | bool HasRealNamedCallbackProperty(String* key); |
| 1741 | |
| 1742 | // Initializes the array to a certain length |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1743 | MUST_USE_RESULT MaybeObject* SetElementsLength(Object* length); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1744 | |
| 1745 | // Get the header size for a JSObject. Used to compute the index of |
| 1746 | // internal fields as well as the number of internal fields. |
| 1747 | inline int GetHeaderSize(); |
| 1748 | |
| 1749 | inline int GetInternalFieldCount(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1750 | inline int GetInternalFieldOffset(int index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1751 | inline Object* GetInternalField(int index); |
| 1752 | inline void SetInternalField(int index, Object* value); |
| 1753 | |
| 1754 | // Lookup a property. If found, the result is valid and has |
| 1755 | // detailed information. |
| 1756 | void LocalLookup(String* name, LookupResult* result); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1757 | |
| 1758 | // The following lookup functions skip interceptors. |
| 1759 | void LocalLookupRealNamedProperty(String* name, LookupResult* result); |
| 1760 | void LookupRealNamedProperty(String* name, LookupResult* result); |
| 1761 | void LookupRealNamedPropertyInPrototypes(String* name, LookupResult* result); |
| 1762 | void LookupCallbackSetterInPrototypes(String* name, LookupResult* result); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1763 | MUST_USE_RESULT MaybeObject* SetElementWithCallbackSetterInPrototypes( |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 1764 | uint32_t index, Object* value, bool* found, StrictModeFlag strict_mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1765 | void LookupCallback(String* name, LookupResult* result); |
| 1766 | |
| 1767 | // Returns the number of properties on this object filtering out properties |
| 1768 | // with the specified attributes (ignoring interceptors). |
| 1769 | int NumberOfLocalProperties(PropertyAttributes filter); |
| 1770 | // Returns the number of enumerable properties (ignoring interceptors). |
| 1771 | int NumberOfEnumProperties(); |
| 1772 | // Fill in details for properties into storage starting at the specified |
| 1773 | // index. |
| 1774 | void GetLocalPropertyNames(FixedArray* storage, int index); |
| 1775 | |
| 1776 | // Returns the number of properties on this object filtering out properties |
| 1777 | // with the specified attributes (ignoring interceptors). |
| 1778 | int NumberOfLocalElements(PropertyAttributes filter); |
| 1779 | // Returns the number of enumerable elements (ignoring interceptors). |
| 1780 | int NumberOfEnumElements(); |
| 1781 | // Returns the number of elements on this object filtering out elements |
| 1782 | // with the specified attributes (ignoring interceptors). |
| 1783 | int GetLocalElementKeys(FixedArray* storage, PropertyAttributes filter); |
| 1784 | // Count and fill in the enumerable elements into storage. |
| 1785 | // (storage->length() == NumberOfEnumElements()). |
| 1786 | // If storage is NULL, will count the elements without adding |
| 1787 | // them to any storage. |
| 1788 | // Returns the number of enumerable elements. |
| 1789 | int GetEnumElementKeys(FixedArray* storage); |
| 1790 | |
| 1791 | // Add a property to a fast-case object using a map transition to |
| 1792 | // new_map. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1793 | MUST_USE_RESULT MaybeObject* AddFastPropertyUsingMap(Map* new_map, |
| 1794 | String* name, |
| 1795 | Object* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1796 | |
| 1797 | // Add a constant function property to a fast-case object. |
| 1798 | // This leaves a CONSTANT_TRANSITION in the old map, and |
| 1799 | // if it is called on a second object with this map, a |
| 1800 | // normal property is added instead, with a map transition. |
| 1801 | // This avoids the creation of many maps with the same constant |
| 1802 | // function, all orphaned. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1803 | MUST_USE_RESULT MaybeObject* AddConstantFunctionProperty( |
| 1804 | String* name, |
| 1805 | JSFunction* function, |
| 1806 | PropertyAttributes attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1807 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1808 | MUST_USE_RESULT MaybeObject* ReplaceSlowProperty( |
| 1809 | String* name, |
| 1810 | Object* value, |
| 1811 | PropertyAttributes attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1812 | |
| 1813 | // Converts a descriptor of any other type to a real field, |
| 1814 | // backed by the properties array. Descriptors of visible |
| 1815 | // types, such as CONSTANT_FUNCTION, keep their enumeration order. |
| 1816 | // Converts the descriptor on the original object's map to a |
| 1817 | // 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] | 1818 | MUST_USE_RESULT MaybeObject* ConvertDescriptorToFieldAndMapTransition( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1819 | String* name, |
| 1820 | Object* new_value, |
| 1821 | PropertyAttributes attributes); |
| 1822 | |
| 1823 | // Converts a descriptor of any other type to a real field, |
| 1824 | // backed by the properties array. Descriptors of visible |
| 1825 | // types, such as CONSTANT_FUNCTION, keep their enumeration order. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1826 | MUST_USE_RESULT MaybeObject* ConvertDescriptorToField( |
| 1827 | String* name, |
| 1828 | Object* new_value, |
| 1829 | PropertyAttributes attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1830 | |
| 1831 | // Add a property to a fast-case object. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1832 | MUST_USE_RESULT MaybeObject* AddFastProperty(String* name, |
| 1833 | Object* value, |
| 1834 | PropertyAttributes attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1835 | |
| 1836 | // Add a property to a slow-case object. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1837 | MUST_USE_RESULT MaybeObject* AddSlowProperty(String* name, |
| 1838 | Object* value, |
| 1839 | PropertyAttributes attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1840 | |
| 1841 | // Add a property to an object. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1842 | MUST_USE_RESULT MaybeObject* AddProperty(String* name, |
| 1843 | Object* value, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1844 | PropertyAttributes attributes, |
| 1845 | StrictModeFlag strict_mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1846 | |
| 1847 | // Convert the object to use the canonical dictionary |
| 1848 | // representation. If the object is expected to have additional properties |
| 1849 | // added this number can be indicated to have the backing store allocated to |
| 1850 | // an initial capacity for holding these properties. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1851 | MUST_USE_RESULT MaybeObject* NormalizeProperties( |
| 1852 | PropertyNormalizationMode mode, |
| 1853 | int expected_additional_properties); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 1854 | |
| 1855 | // Convert and update the elements backing store to be a NumberDictionary |
| 1856 | // dictionary. Returns the backing after conversion. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1857 | MUST_USE_RESULT MaybeObject* NormalizeElements(); |
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* UpdateMapCodeCache(String* name, Code* code); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1860 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1861 | // Transform slow named properties to fast variants. |
| 1862 | // Returns failure if allocation failed. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1863 | MUST_USE_RESULT MaybeObject* TransformToFastProperties( |
| 1864 | int unused_property_fields); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1865 | |
| 1866 | // Access fast-case object properties at index. |
| 1867 | inline Object* FastPropertyAt(int index); |
| 1868 | inline Object* FastPropertyAtPut(int index, Object* value); |
| 1869 | |
| 1870 | // Access to in object properties. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1871 | inline int GetInObjectPropertyOffset(int index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1872 | inline Object* InObjectPropertyAt(int index); |
| 1873 | inline Object* InObjectPropertyAtPut(int index, |
| 1874 | Object* value, |
| 1875 | WriteBarrierMode mode |
| 1876 | = UPDATE_WRITE_BARRIER); |
| 1877 | |
| 1878 | // initializes the body after properties slot, properties slot is |
| 1879 | // initialized by set_properties |
| 1880 | // Note: this call does not update write barrier, it is caller's |
| 1881 | // reponsibility to ensure that *v* can be collected without WB here. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1882 | inline void InitializeBody(int object_size, Object* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1883 | |
| 1884 | // Check whether this object references another object |
| 1885 | bool ReferencesObject(Object* obj); |
| 1886 | |
| 1887 | // Casting. |
| 1888 | static inline JSObject* cast(Object* obj); |
| 1889 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1890 | // Disalow further properties to be added to the object. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1891 | MUST_USE_RESULT MaybeObject* PreventExtensions(); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1892 | |
| 1893 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1894 | // Dispatched behavior. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1895 | void JSObjectShortPrint(StringStream* accumulator); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1896 | #ifdef OBJECT_PRINT |
| 1897 | inline void JSObjectPrint() { |
| 1898 | JSObjectPrint(stdout); |
| 1899 | } |
| 1900 | void JSObjectPrint(FILE* out); |
| 1901 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1902 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1903 | void JSObjectVerify(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1904 | #endif |
| 1905 | #ifdef OBJECT_PRINT |
| 1906 | inline void PrintProperties() { |
| 1907 | PrintProperties(stdout); |
| 1908 | } |
| 1909 | void PrintProperties(FILE* out); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1910 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1911 | inline void PrintElements() { |
| 1912 | PrintElements(stdout); |
| 1913 | } |
| 1914 | void PrintElements(FILE* out); |
| 1915 | #endif |
| 1916 | |
| 1917 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1918 | // Structure for collecting spill information about JSObjects. |
| 1919 | class SpillInformation { |
| 1920 | public: |
| 1921 | void Clear(); |
| 1922 | void Print(); |
| 1923 | int number_of_objects_; |
| 1924 | int number_of_objects_with_fast_properties_; |
| 1925 | int number_of_objects_with_fast_elements_; |
| 1926 | int number_of_fast_used_fields_; |
| 1927 | int number_of_fast_unused_fields_; |
| 1928 | int number_of_slow_used_properties_; |
| 1929 | int number_of_slow_unused_properties_; |
| 1930 | int number_of_fast_used_elements_; |
| 1931 | int number_of_fast_unused_elements_; |
| 1932 | int number_of_slow_used_elements_; |
| 1933 | int number_of_slow_unused_elements_; |
| 1934 | }; |
| 1935 | |
| 1936 | void IncrementSpillStatistics(SpillInformation* info); |
| 1937 | #endif |
| 1938 | Object* SlowReverseLookup(Object* value); |
| 1939 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1940 | // Maximal number of fast properties for the JSObject. Used to |
| 1941 | // restrict the number of map transitions to avoid an explosion in |
| 1942 | // the number of maps for objects used as dictionaries. |
| 1943 | inline int MaxFastProperties(); |
| 1944 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1945 | // Maximal number of elements (numbered 0 .. kMaxElementCount - 1). |
| 1946 | // Also maximal value of JSArray's length property. |
| 1947 | static const uint32_t kMaxElementCount = 0xffffffffu; |
| 1948 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1949 | static const uint32_t kMaxGap = 1024; |
| 1950 | static const int kMaxFastElementsLength = 5000; |
| 1951 | static const int kInitialMaxFastElementArray = 100000; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1952 | static const int kMaxFastProperties = 12; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1953 | static const int kMaxInstanceSize = 255 * kPointerSize; |
| 1954 | // When extending the backing storage for property values, we increase |
| 1955 | // its size by more than the 1 entry necessary, so sequentially adding fields |
| 1956 | // to the same object requires fewer allocations and copies. |
| 1957 | static const int kFieldsAdded = 3; |
| 1958 | |
| 1959 | // Layout description. |
| 1960 | static const int kPropertiesOffset = HeapObject::kHeaderSize; |
| 1961 | static const int kElementsOffset = kPropertiesOffset + kPointerSize; |
| 1962 | static const int kHeaderSize = kElementsOffset + kPointerSize; |
| 1963 | |
| 1964 | STATIC_CHECK(kHeaderSize == Internals::kJSObjectHeaderSize); |
| 1965 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1966 | class BodyDescriptor : public FlexibleBodyDescriptor<kPropertiesOffset> { |
| 1967 | public: |
| 1968 | static inline int SizeOf(Map* map, HeapObject* object); |
| 1969 | }; |
| 1970 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1971 | private: |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1972 | MUST_USE_RESULT MaybeObject* GetElementWithCallback(Object* receiver, |
| 1973 | Object* structure, |
| 1974 | uint32_t index, |
| 1975 | Object* holder); |
| 1976 | MaybeObject* SetElementWithCallback(Object* structure, |
| 1977 | uint32_t index, |
| 1978 | Object* value, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 1979 | JSObject* holder, |
| 1980 | StrictModeFlag strict_mode); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1981 | MUST_USE_RESULT MaybeObject* SetElementWithInterceptor( |
| 1982 | uint32_t index, |
| 1983 | Object* value, |
| 1984 | StrictModeFlag strict_mode, |
| 1985 | bool check_prototype); |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 1986 | MUST_USE_RESULT MaybeObject* SetElementWithoutInterceptor( |
| 1987 | uint32_t index, |
| 1988 | Object* value, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1989 | StrictModeFlag strict_mode, |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 1990 | bool check_prototype); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1991 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1992 | MaybeObject* GetElementPostInterceptor(Object* receiver, uint32_t index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1993 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1994 | MUST_USE_RESULT MaybeObject* DeletePropertyPostInterceptor(String* name, |
| 1995 | DeleteMode mode); |
| 1996 | MUST_USE_RESULT MaybeObject* DeletePropertyWithInterceptor(String* name); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1997 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1998 | MUST_USE_RESULT MaybeObject* DeleteElementPostInterceptor(uint32_t index, |
| 1999 | DeleteMode mode); |
| 2000 | MUST_USE_RESULT MaybeObject* DeleteElementWithInterceptor(uint32_t index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2001 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 2002 | MUST_USE_RESULT MaybeObject* DeleteFastElement(uint32_t index); |
| 2003 | MUST_USE_RESULT MaybeObject* DeleteDictionaryElement(uint32_t index, |
| 2004 | DeleteMode mode); |
| 2005 | |
| 2006 | bool ReferencesObjectFromElements(FixedArray* elements, |
| 2007 | ElementsKind kind, |
| 2008 | Object* object); |
| 2009 | bool HasElementInElements(FixedArray* elements, |
| 2010 | ElementsKind kind, |
| 2011 | uint32_t index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2012 | |
| 2013 | // Returns true if most of the elements backing storage is used. |
| 2014 | bool HasDenseElements(); |
| 2015 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2016 | bool CanSetCallback(String* name); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2017 | MUST_USE_RESULT MaybeObject* SetElementCallback( |
| 2018 | uint32_t index, |
| 2019 | Object* structure, |
| 2020 | PropertyAttributes attributes); |
| 2021 | MUST_USE_RESULT MaybeObject* SetPropertyCallback( |
| 2022 | String* name, |
| 2023 | Object* structure, |
| 2024 | PropertyAttributes attributes); |
| 2025 | MUST_USE_RESULT MaybeObject* DefineGetterSetter( |
| 2026 | String* name, |
| 2027 | PropertyAttributes attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2028 | |
| 2029 | void LookupInDescriptor(String* name, LookupResult* result); |
| 2030 | |
| 2031 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSObject); |
| 2032 | }; |
| 2033 | |
| 2034 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 2035 | // Common superclass for FixedArrays that allow implementations to share |
| 2036 | // common accessors and some code paths. |
| 2037 | class FixedArrayBase: public HeapObject { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2038 | public: |
| 2039 | // [length]: length of the array. |
| 2040 | inline int length(); |
| 2041 | inline void set_length(int value); |
| 2042 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 2043 | inline static FixedArrayBase* cast(Object* object); |
| 2044 | |
| 2045 | // Layout description. |
| 2046 | // Length is smi tagged when it is stored. |
| 2047 | static const int kLengthOffset = HeapObject::kHeaderSize; |
| 2048 | static const int kHeaderSize = kLengthOffset + kPointerSize; |
| 2049 | }; |
| 2050 | |
| 2051 | |
| 2052 | // FixedArray describes fixed-sized arrays with element type Object*. |
| 2053 | class FixedArray: public FixedArrayBase { |
| 2054 | public: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2055 | // Setter and getter for elements. |
| 2056 | inline Object* get(int index); |
| 2057 | // Setter that uses write barrier. |
| 2058 | inline void set(int index, Object* value); |
| 2059 | |
| 2060 | // Setter that doesn't need write barrier). |
| 2061 | inline void set(int index, Smi* value); |
| 2062 | // Setter with explicit barrier mode. |
| 2063 | inline void set(int index, Object* value, WriteBarrierMode mode); |
| 2064 | |
| 2065 | // Setters for frequently used oddballs located in old space. |
| 2066 | inline void set_undefined(int index); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2067 | // TODO(isolates): duplicate. |
| 2068 | inline void set_undefined(Heap* heap, int index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2069 | inline void set_null(int index); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2070 | // TODO(isolates): duplicate. |
| 2071 | inline void set_null(Heap* heap, int index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2072 | inline void set_the_hole(int index); |
| 2073 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2074 | // Setters with less debug checks for the GC to use. |
| 2075 | inline void set_unchecked(int index, Smi* value); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2076 | inline void set_null_unchecked(Heap* heap, int index); |
| 2077 | inline void set_unchecked(Heap* heap, int index, Object* value, |
| 2078 | WriteBarrierMode mode); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2079 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2080 | // Gives access to raw memory which stores the array's data. |
| 2081 | inline Object** data_start(); |
| 2082 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2083 | // Copy operations. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2084 | MUST_USE_RESULT inline MaybeObject* Copy(); |
| 2085 | MUST_USE_RESULT MaybeObject* CopySize(int new_length); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2086 | |
| 2087 | // Add the elements of a JSArray to this FixedArray. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2088 | MUST_USE_RESULT MaybeObject* AddKeysFromJSArray(JSArray* array); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2089 | |
| 2090 | // Compute the union of this and other. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2091 | MUST_USE_RESULT MaybeObject* UnionOfKeys(FixedArray* other); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2092 | |
| 2093 | // Copy a sub array from the receiver to dest. |
| 2094 | void CopyTo(int pos, FixedArray* dest, int dest_pos, int len); |
| 2095 | |
| 2096 | // Garbage collection support. |
| 2097 | static int SizeFor(int length) { return kHeaderSize + length * kPointerSize; } |
| 2098 | |
| 2099 | // Code Generation support. |
| 2100 | static int OffsetOfElementAt(int index) { return SizeFor(index); } |
| 2101 | |
| 2102 | // Casting. |
| 2103 | static inline FixedArray* cast(Object* obj); |
| 2104 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2105 | // Maximal allowed size, in bytes, of a single FixedArray. |
| 2106 | // Prevents overflowing size computations, as well as extreme memory |
| 2107 | // consumption. |
| 2108 | static const int kMaxSize = 512 * MB; |
| 2109 | // Maximally allowed length of a FixedArray. |
| 2110 | static const int kMaxLength = (kMaxSize - kHeaderSize) / kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2111 | |
| 2112 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2113 | #ifdef OBJECT_PRINT |
| 2114 | inline void FixedArrayPrint() { |
| 2115 | FixedArrayPrint(stdout); |
| 2116 | } |
| 2117 | void FixedArrayPrint(FILE* out); |
| 2118 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2119 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2120 | void FixedArrayVerify(); |
| 2121 | // Checks if two FixedArrays have identical contents. |
| 2122 | bool IsEqualTo(FixedArray* other); |
| 2123 | #endif |
| 2124 | |
| 2125 | // Swap two elements in a pair of arrays. If this array and the |
| 2126 | // numbers array are the same object, the elements are only swapped |
| 2127 | // once. |
| 2128 | void SwapPairs(FixedArray* numbers, int i, int j); |
| 2129 | |
| 2130 | // Sort prefix of this array and the numbers array as pairs wrt. the |
| 2131 | // numbers. If the numbers array and the this array are the same |
| 2132 | // object, the prefix of this array is sorted. |
| 2133 | void SortPairs(FixedArray* numbers, uint32_t len); |
| 2134 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2135 | class BodyDescriptor : public FlexibleBodyDescriptor<kHeaderSize> { |
| 2136 | public: |
| 2137 | static inline int SizeOf(Map* map, HeapObject* object) { |
| 2138 | return SizeFor(reinterpret_cast<FixedArray*>(object)->length()); |
| 2139 | } |
| 2140 | }; |
| 2141 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2142 | protected: |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 2143 | // Set operation on FixedArray without using write barriers. Can |
| 2144 | // only be used for storing old space objects or smis. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2145 | static inline void fast_set(FixedArray* array, int index, Object* value); |
| 2146 | |
| 2147 | private: |
| 2148 | DISALLOW_IMPLICIT_CONSTRUCTORS(FixedArray); |
| 2149 | }; |
| 2150 | |
| 2151 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 2152 | // FixedDoubleArray describes fixed-sized arrays with element type double. |
| 2153 | class FixedDoubleArray: public FixedArrayBase { |
| 2154 | public: |
| 2155 | inline void Initialize(FixedArray* from); |
| 2156 | inline void Initialize(FixedDoubleArray* from); |
| 2157 | inline void Initialize(NumberDictionary* from); |
| 2158 | |
| 2159 | // Setter and getter for elements. |
| 2160 | inline double get(int index); |
| 2161 | inline void set(int index, double value); |
| 2162 | inline void set_the_hole(int index); |
| 2163 | |
| 2164 | // Checking for the hole. |
| 2165 | inline bool is_the_hole(int index); |
| 2166 | |
| 2167 | // Garbage collection support. |
| 2168 | inline static int SizeFor(int length) { |
| 2169 | return kHeaderSize + length * kDoubleSize; |
| 2170 | } |
| 2171 | |
| 2172 | // Code Generation support. |
| 2173 | static int OffsetOfElementAt(int index) { return SizeFor(index); } |
| 2174 | |
| 2175 | inline static bool is_the_hole_nan(double value); |
| 2176 | inline static double hole_nan_as_double(); |
| 2177 | inline static double canonical_not_the_hole_nan_as_double(); |
| 2178 | |
| 2179 | // Casting. |
| 2180 | static inline FixedDoubleArray* cast(Object* obj); |
| 2181 | |
| 2182 | // Maximal allowed size, in bytes, of a single FixedDoubleArray. |
| 2183 | // Prevents overflowing size computations, as well as extreme memory |
| 2184 | // consumption. |
| 2185 | static const int kMaxSize = 512 * MB; |
| 2186 | // Maximally allowed length of a FixedArray. |
| 2187 | static const int kMaxLength = (kMaxSize - kHeaderSize) / kDoubleSize; |
| 2188 | |
| 2189 | // Dispatched behavior. |
| 2190 | #ifdef OBJECT_PRINT |
| 2191 | inline void FixedDoubleArrayPrint() { |
| 2192 | FixedDoubleArrayPrint(stdout); |
| 2193 | } |
| 2194 | void FixedDoubleArrayPrint(FILE* out); |
| 2195 | #endif |
| 2196 | |
| 2197 | #ifdef DEBUG |
| 2198 | void FixedDoubleArrayVerify(); |
| 2199 | #endif |
| 2200 | |
| 2201 | private: |
| 2202 | DISALLOW_IMPLICIT_CONSTRUCTORS(FixedDoubleArray); |
| 2203 | }; |
| 2204 | |
| 2205 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2206 | // DescriptorArrays are fixed arrays used to hold instance descriptors. |
| 2207 | // The format of the these objects is: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2208 | // TODO(1399): It should be possible to make room for bit_field3 in the map |
| 2209 | // without overloading the instance descriptors field in the map |
| 2210 | // (and storing it in the DescriptorArray when the map has one). |
| 2211 | // [0]: storage for bit_field3 for Map owning this object (Smi) |
| 2212 | // [1]: point to a fixed array with (value, detail) pairs. |
| 2213 | // [2]: next enumeration index (Smi), or pointer to small fixed array: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2214 | // [0]: next enumeration index (Smi) |
| 2215 | // [1]: pointer to fixed array with enum cache |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2216 | // [3]: first key |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2217 | // [length() - 1]: last key |
| 2218 | // |
| 2219 | class DescriptorArray: public FixedArray { |
| 2220 | public: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2221 | // Returns true for both shared empty_descriptor_array and for smis, which the |
| 2222 | // map uses to encode additional bit fields when the descriptor array is not |
| 2223 | // yet used. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2224 | inline bool IsEmpty(); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2225 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2226 | // Returns the number of descriptors in the array. |
| 2227 | int number_of_descriptors() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2228 | ASSERT(length() > kFirstIndex || IsEmpty()); |
| 2229 | int len = length(); |
| 2230 | return len <= kFirstIndex ? 0 : len - kFirstIndex; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2231 | } |
| 2232 | |
| 2233 | int NextEnumerationIndex() { |
| 2234 | if (IsEmpty()) return PropertyDetails::kInitialIndex; |
| 2235 | Object* obj = get(kEnumerationIndexIndex); |
| 2236 | if (obj->IsSmi()) { |
| 2237 | return Smi::cast(obj)->value(); |
| 2238 | } else { |
| 2239 | Object* index = FixedArray::cast(obj)->get(kEnumCacheBridgeEnumIndex); |
| 2240 | return Smi::cast(index)->value(); |
| 2241 | } |
| 2242 | } |
| 2243 | |
| 2244 | // Set next enumeration index and flush any enum cache. |
| 2245 | void SetNextEnumerationIndex(int value) { |
| 2246 | if (!IsEmpty()) { |
| 2247 | fast_set(this, kEnumerationIndexIndex, Smi::FromInt(value)); |
| 2248 | } |
| 2249 | } |
| 2250 | bool HasEnumCache() { |
| 2251 | return !IsEmpty() && !get(kEnumerationIndexIndex)->IsSmi(); |
| 2252 | } |
| 2253 | |
| 2254 | Object* GetEnumCache() { |
| 2255 | ASSERT(HasEnumCache()); |
| 2256 | FixedArray* bridge = FixedArray::cast(get(kEnumerationIndexIndex)); |
| 2257 | return bridge->get(kEnumCacheBridgeCacheIndex); |
| 2258 | } |
| 2259 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2260 | // TODO(1399): It should be possible to make room for bit_field3 in the map |
| 2261 | // without overloading the instance descriptors field in the map |
| 2262 | // (and storing it in the DescriptorArray when the map has one). |
| 2263 | inline int bit_field3_storage(); |
| 2264 | inline void set_bit_field3_storage(int value); |
| 2265 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2266 | // Initialize or change the enum cache, |
| 2267 | // using the supplied storage for the small "bridge". |
| 2268 | void SetEnumCache(FixedArray* bridge_storage, FixedArray* new_cache); |
| 2269 | |
| 2270 | // Accessors for fetching instance descriptor at descriptor number. |
| 2271 | inline String* GetKey(int descriptor_number); |
| 2272 | inline Object* GetValue(int descriptor_number); |
| 2273 | inline Smi* GetDetails(int descriptor_number); |
| 2274 | inline PropertyType GetType(int descriptor_number); |
| 2275 | inline int GetFieldIndex(int descriptor_number); |
| 2276 | inline JSFunction* GetConstantFunction(int descriptor_number); |
| 2277 | inline Object* GetCallbacksObject(int descriptor_number); |
| 2278 | inline AccessorDescriptor* GetCallbacks(int descriptor_number); |
| 2279 | inline bool IsProperty(int descriptor_number); |
| 2280 | inline bool IsTransition(int descriptor_number); |
| 2281 | inline bool IsNullDescriptor(int descriptor_number); |
| 2282 | inline bool IsDontEnum(int descriptor_number); |
| 2283 | |
| 2284 | // Accessor for complete descriptor. |
| 2285 | inline void Get(int descriptor_number, Descriptor* desc); |
| 2286 | inline void Set(int descriptor_number, Descriptor* desc); |
| 2287 | |
| 2288 | // Transfer complete descriptor from another descriptor array to |
| 2289 | // this one. |
| 2290 | inline void CopyFrom(int index, DescriptorArray* src, int src_index); |
| 2291 | |
| 2292 | // Copy the descriptor array, insert a new descriptor and optionally |
| 2293 | // remove map transitions. If the descriptor is already present, it is |
| 2294 | // replaced. If a replaced descriptor is a real property (not a transition |
| 2295 | // or null), its enumeration index is kept as is. |
| 2296 | // If adding a real property, map transitions must be removed. If adding |
| 2297 | // a transition, they must not be removed. All null descriptors are removed. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2298 | MUST_USE_RESULT MaybeObject* CopyInsert(Descriptor* descriptor, |
| 2299 | TransitionFlag transition_flag); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2300 | |
| 2301 | // Remove all transitions. Return a copy of the array with all transitions |
| 2302 | // 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] | 2303 | MUST_USE_RESULT MaybeObject* RemoveTransitions(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2304 | |
| 2305 | // Sort the instance descriptors by the hash codes of their keys. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 2306 | // Does not check for duplicates. |
| 2307 | void SortUnchecked(); |
| 2308 | |
| 2309 | // Sort the instance descriptors by the hash codes of their keys. |
| 2310 | // Checks the result for duplicates. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2311 | void Sort(); |
| 2312 | |
| 2313 | // Search the instance descriptors for given name. |
| 2314 | inline int Search(String* name); |
| 2315 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2316 | // As the above, but uses DescriptorLookupCache and updates it when |
| 2317 | // necessary. |
| 2318 | inline int SearchWithCache(String* name); |
| 2319 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2320 | // Tells whether the name is present int the array. |
| 2321 | bool Contains(String* name) { return kNotFound != Search(name); } |
| 2322 | |
| 2323 | // Perform a binary search in the instance descriptors represented |
| 2324 | // by this fixed array. low and high are descriptor indices. If there |
| 2325 | // are three instance descriptors in this array it should be called |
| 2326 | // with low=0 and high=2. |
| 2327 | int BinarySearch(String* name, int low, int high); |
| 2328 | |
| 2329 | // Perform a linear search in the instance descriptors represented |
| 2330 | // by this fixed array. len is the number of descriptor indices that are |
| 2331 | // valid. Does not require the descriptors to be sorted. |
| 2332 | int LinearSearch(String* name, int len); |
| 2333 | |
| 2334 | // Allocates a DescriptorArray, but returns the singleton |
| 2335 | // empty descriptor array object if number_of_descriptors is 0. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2336 | MUST_USE_RESULT static MaybeObject* Allocate(int number_of_descriptors); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2337 | |
| 2338 | // Casting. |
| 2339 | static inline DescriptorArray* cast(Object* obj); |
| 2340 | |
| 2341 | // Constant for denoting key was not found. |
| 2342 | static const int kNotFound = -1; |
| 2343 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2344 | static const int kBitField3StorageIndex = 0; |
| 2345 | static const int kContentArrayIndex = 1; |
| 2346 | static const int kEnumerationIndexIndex = 2; |
| 2347 | static const int kFirstIndex = 3; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2348 | |
| 2349 | // The length of the "bridge" to the enum cache. |
| 2350 | static const int kEnumCacheBridgeLength = 2; |
| 2351 | static const int kEnumCacheBridgeEnumIndex = 0; |
| 2352 | static const int kEnumCacheBridgeCacheIndex = 1; |
| 2353 | |
| 2354 | // Layout description. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2355 | static const int kBitField3StorageOffset = FixedArray::kHeaderSize; |
| 2356 | static const int kContentArrayOffset = kBitField3StorageOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2357 | static const int kEnumerationIndexOffset = kContentArrayOffset + kPointerSize; |
| 2358 | static const int kFirstOffset = kEnumerationIndexOffset + kPointerSize; |
| 2359 | |
| 2360 | // Layout description for the bridge array. |
| 2361 | static const int kEnumCacheBridgeEnumOffset = FixedArray::kHeaderSize; |
| 2362 | static const int kEnumCacheBridgeCacheOffset = |
| 2363 | kEnumCacheBridgeEnumOffset + kPointerSize; |
| 2364 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2365 | #ifdef OBJECT_PRINT |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2366 | // Print all the descriptors. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2367 | inline void PrintDescriptors() { |
| 2368 | PrintDescriptors(stdout); |
| 2369 | } |
| 2370 | void PrintDescriptors(FILE* out); |
| 2371 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2372 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2373 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2374 | // Is the descriptor array sorted and without duplicates? |
| 2375 | bool IsSortedNoDuplicates(); |
| 2376 | |
| 2377 | // Are two DescriptorArrays equal? |
| 2378 | bool IsEqualTo(DescriptorArray* other); |
| 2379 | #endif |
| 2380 | |
| 2381 | // The maximum number of descriptors we want in a descriptor array (should |
| 2382 | // fit in a page). |
| 2383 | static const int kMaxNumberOfDescriptors = 1024 + 512; |
| 2384 | |
| 2385 | private: |
| 2386 | // Conversion from descriptor number to array indices. |
| 2387 | static int ToKeyIndex(int descriptor_number) { |
| 2388 | return descriptor_number+kFirstIndex; |
| 2389 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2390 | |
| 2391 | static int ToDetailsIndex(int descriptor_number) { |
| 2392 | return (descriptor_number << 1) + 1; |
| 2393 | } |
| 2394 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2395 | static int ToValueIndex(int descriptor_number) { |
| 2396 | return descriptor_number << 1; |
| 2397 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2398 | |
| 2399 | bool is_null_descriptor(int descriptor_number) { |
| 2400 | return PropertyDetails(GetDetails(descriptor_number)).type() == |
| 2401 | NULL_DESCRIPTOR; |
| 2402 | } |
| 2403 | // Swap operation on FixedArray without using write barriers. |
| 2404 | static inline void fast_swap(FixedArray* array, int first, int second); |
| 2405 | |
| 2406 | // Swap descriptor first and second. |
| 2407 | inline void Swap(int first, int second); |
| 2408 | |
| 2409 | FixedArray* GetContentArray() { |
| 2410 | return FixedArray::cast(get(kContentArrayIndex)); |
| 2411 | } |
| 2412 | DISALLOW_IMPLICIT_CONSTRUCTORS(DescriptorArray); |
| 2413 | }; |
| 2414 | |
| 2415 | |
| 2416 | // HashTable is a subclass of FixedArray that implements a hash table |
| 2417 | // that uses open addressing and quadratic probing. |
| 2418 | // |
| 2419 | // In order for the quadratic probing to work, elements that have not |
| 2420 | // yet been used and elements that have been deleted are |
| 2421 | // distinguished. Probing continues when deleted elements are |
| 2422 | // encountered and stops when unused elements are encountered. |
| 2423 | // |
| 2424 | // - Elements with key == undefined have not been used yet. |
| 2425 | // - Elements with key == null have been deleted. |
| 2426 | // |
| 2427 | // The hash table class is parameterized with a Shape and a Key. |
| 2428 | // Shape must be a class with the following interface: |
| 2429 | // class ExampleShape { |
| 2430 | // public: |
| 2431 | // // Tells whether key matches other. |
| 2432 | // static bool IsMatch(Key key, Object* other); |
| 2433 | // // Returns the hash value for key. |
| 2434 | // static uint32_t Hash(Key key); |
| 2435 | // // Returns the hash value for object. |
| 2436 | // static uint32_t HashForObject(Key key, Object* object); |
| 2437 | // // Convert key to an object. |
| 2438 | // static inline Object* AsObject(Key key); |
| 2439 | // // The prefix size indicates number of elements in the beginning |
| 2440 | // // of the backing storage. |
| 2441 | // static const int kPrefixSize = ..; |
| 2442 | // // The Element size indicates number of elements per entry. |
| 2443 | // static const int kEntrySize = ..; |
| 2444 | // }; |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2445 | // The prefix size indicates an amount of memory in the |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2446 | // beginning of the backing storage that can be used for non-element |
| 2447 | // information by subclasses. |
| 2448 | |
| 2449 | template<typename Shape, typename Key> |
| 2450 | class HashTable: public FixedArray { |
| 2451 | public: |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2452 | // Returns the number of elements in the hash table. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2453 | int NumberOfElements() { |
| 2454 | return Smi::cast(get(kNumberOfElementsIndex))->value(); |
| 2455 | } |
| 2456 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2457 | // Returns the number of deleted elements in the hash table. |
| 2458 | int NumberOfDeletedElements() { |
| 2459 | return Smi::cast(get(kNumberOfDeletedElementsIndex))->value(); |
| 2460 | } |
| 2461 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2462 | // Returns the capacity of the hash table. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2463 | int Capacity() { |
| 2464 | return Smi::cast(get(kCapacityIndex))->value(); |
| 2465 | } |
| 2466 | |
| 2467 | // ElementAdded should be called whenever an element is added to a |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2468 | // hash table. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2469 | void ElementAdded() { SetNumberOfElements(NumberOfElements() + 1); } |
| 2470 | |
| 2471 | // ElementRemoved should be called whenever an element is removed from |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2472 | // a hash table. |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2473 | void ElementRemoved() { |
| 2474 | SetNumberOfElements(NumberOfElements() - 1); |
| 2475 | SetNumberOfDeletedElements(NumberOfDeletedElements() + 1); |
| 2476 | } |
| 2477 | void ElementsRemoved(int n) { |
| 2478 | SetNumberOfElements(NumberOfElements() - n); |
| 2479 | SetNumberOfDeletedElements(NumberOfDeletedElements() + n); |
| 2480 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2481 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2482 | // Returns a new HashTable object. Might return Failure. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2483 | MUST_USE_RESULT static MaybeObject* Allocate( |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2484 | int at_least_space_for, |
| 2485 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2486 | |
| 2487 | // Returns the key at entry. |
| 2488 | Object* KeyAt(int entry) { return get(EntryToIndex(entry)); } |
| 2489 | |
| 2490 | // Tells whether k is a real key. Null and undefined are not allowed |
| 2491 | // as keys and can be used to indicate missing or deleted elements. |
| 2492 | bool IsKey(Object* k) { |
| 2493 | return !k->IsNull() && !k->IsUndefined(); |
| 2494 | } |
| 2495 | |
| 2496 | // Garbage collection support. |
| 2497 | void IteratePrefix(ObjectVisitor* visitor); |
| 2498 | void IterateElements(ObjectVisitor* visitor); |
| 2499 | |
| 2500 | // Casting. |
| 2501 | static inline HashTable* cast(Object* obj); |
| 2502 | |
| 2503 | // Compute the probe offset (quadratic probing). |
| 2504 | INLINE(static uint32_t GetProbeOffset(uint32_t n)) { |
| 2505 | return (n + n * n) >> 1; |
| 2506 | } |
| 2507 | |
| 2508 | static const int kNumberOfElementsIndex = 0; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2509 | static const int kNumberOfDeletedElementsIndex = 1; |
| 2510 | static const int kCapacityIndex = 2; |
| 2511 | static const int kPrefixStartIndex = 3; |
| 2512 | static const int kElementsStartIndex = |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2513 | kPrefixStartIndex + Shape::kPrefixSize; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2514 | static const int kEntrySize = Shape::kEntrySize; |
| 2515 | static const int kElementsStartOffset = |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2516 | kHeaderSize + kElementsStartIndex * kPointerSize; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2517 | static const int kCapacityOffset = |
| 2518 | kHeaderSize + kCapacityIndex * kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2519 | |
| 2520 | // Constant used for denoting a absent entry. |
| 2521 | static const int kNotFound = -1; |
| 2522 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2523 | // Maximal capacity of HashTable. Based on maximal length of underlying |
| 2524 | // FixedArray. Staying below kMaxCapacity also ensures that EntryToIndex |
| 2525 | // cannot overflow. |
| 2526 | static const int kMaxCapacity = |
| 2527 | (FixedArray::kMaxLength - kElementsStartOffset) / kEntrySize; |
| 2528 | |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 2529 | // Find entry for key otherwise return kNotFound. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2530 | inline int FindEntry(Key key); |
| 2531 | int FindEntry(Isolate* isolate, Key key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2532 | |
| 2533 | protected: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2534 | // Find the entry at which to insert element with the given key that |
| 2535 | // has the given hash value. |
| 2536 | uint32_t FindInsertionEntry(uint32_t hash); |
| 2537 | |
| 2538 | // Returns the index for an entry (of the key) |
| 2539 | static inline int EntryToIndex(int entry) { |
| 2540 | return (entry * kEntrySize) + kElementsStartIndex; |
| 2541 | } |
| 2542 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2543 | // Update the number of elements in the hash table. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2544 | void SetNumberOfElements(int nof) { |
| 2545 | fast_set(this, kNumberOfElementsIndex, Smi::FromInt(nof)); |
| 2546 | } |
| 2547 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2548 | // Update the number of deleted elements in the hash table. |
| 2549 | void SetNumberOfDeletedElements(int nod) { |
| 2550 | fast_set(this, kNumberOfDeletedElementsIndex, Smi::FromInt(nod)); |
| 2551 | } |
| 2552 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2553 | // Sets the capacity of the hash table. |
| 2554 | void SetCapacity(int capacity) { |
| 2555 | // To scale a computed hash code to fit within the hash table, we |
| 2556 | // use bit-wise AND with a mask, so the capacity must be positive |
| 2557 | // and non-zero. |
| 2558 | ASSERT(capacity > 0); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2559 | ASSERT(capacity <= kMaxCapacity); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2560 | fast_set(this, kCapacityIndex, Smi::FromInt(capacity)); |
| 2561 | } |
| 2562 | |
| 2563 | |
| 2564 | // Returns probe entry. |
| 2565 | static uint32_t GetProbe(uint32_t hash, uint32_t number, uint32_t size) { |
| 2566 | ASSERT(IsPowerOf2(size)); |
| 2567 | return (hash + GetProbeOffset(number)) & (size - 1); |
| 2568 | } |
| 2569 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2570 | static uint32_t FirstProbe(uint32_t hash, uint32_t size) { |
| 2571 | return hash & (size - 1); |
| 2572 | } |
| 2573 | |
| 2574 | static uint32_t NextProbe(uint32_t last, uint32_t number, uint32_t size) { |
| 2575 | return (last + number) & (size - 1); |
| 2576 | } |
| 2577 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 2578 | // Rehashes this hash-table into the new table. |
| 2579 | MUST_USE_RESULT MaybeObject* Rehash(HashTable* new_table, Key key); |
| 2580 | |
| 2581 | // Attempt to shrink hash table after removal of key. |
| 2582 | MUST_USE_RESULT MaybeObject* Shrink(Key key); |
| 2583 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2584 | // Ensure enough space for n additional elements. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2585 | MUST_USE_RESULT MaybeObject* EnsureCapacity(int n, Key key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2586 | }; |
| 2587 | |
| 2588 | |
| 2589 | |
| 2590 | // HashTableKey is an abstract superclass for virtual key behavior. |
| 2591 | class HashTableKey { |
| 2592 | public: |
| 2593 | // Returns whether the other object matches this key. |
| 2594 | virtual bool IsMatch(Object* other) = 0; |
| 2595 | // Returns the hash value for this key. |
| 2596 | virtual uint32_t Hash() = 0; |
| 2597 | // Returns the hash value for object. |
| 2598 | virtual uint32_t HashForObject(Object* key) = 0; |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2599 | // Returns the key object for storing into the hash table. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2600 | // If allocations fails a failure object is returned. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2601 | MUST_USE_RESULT virtual MaybeObject* AsObject() = 0; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2602 | // Required. |
| 2603 | virtual ~HashTableKey() {} |
| 2604 | }; |
| 2605 | |
| 2606 | class SymbolTableShape { |
| 2607 | public: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2608 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2609 | return key->IsMatch(value); |
| 2610 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2611 | static inline uint32_t Hash(HashTableKey* key) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2612 | return key->Hash(); |
| 2613 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2614 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2615 | return key->HashForObject(object); |
| 2616 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2617 | MUST_USE_RESULT static inline MaybeObject* AsObject(HashTableKey* key) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2618 | return key->AsObject(); |
| 2619 | } |
| 2620 | |
| 2621 | static const int kPrefixSize = 0; |
| 2622 | static const int kEntrySize = 1; |
| 2623 | }; |
| 2624 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2625 | class SeqAsciiString; |
| 2626 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2627 | // SymbolTable. |
| 2628 | // |
| 2629 | // No special elements in the prefix and the element size is 1 |
| 2630 | // because only the symbol itself (the key) needs to be stored. |
| 2631 | class SymbolTable: public HashTable<SymbolTableShape, HashTableKey*> { |
| 2632 | public: |
| 2633 | // Find symbol in the symbol table. If it is not there yet, it is |
| 2634 | // added. The return value is the symbol table which might have |
| 2635 | // been enlarged. If the return value is not a failure, the symbol |
| 2636 | // pointer *s is set to the symbol found. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2637 | MUST_USE_RESULT MaybeObject* LookupSymbol(Vector<const char> str, Object** s); |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 2638 | MUST_USE_RESULT MaybeObject* LookupAsciiSymbol(Vector<const char> str, |
| 2639 | Object** s); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2640 | MUST_USE_RESULT MaybeObject* LookupSubStringAsciiSymbol( |
| 2641 | Handle<SeqAsciiString> str, |
| 2642 | int from, |
| 2643 | int length, |
| 2644 | Object** s); |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 2645 | MUST_USE_RESULT MaybeObject* LookupTwoByteSymbol(Vector<const uc16> str, |
| 2646 | Object** s); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2647 | MUST_USE_RESULT MaybeObject* LookupString(String* key, Object** s); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2648 | |
| 2649 | // Looks up a symbol that is equal to the given string and returns |
| 2650 | // true if it is found, assigning the symbol to the given output |
| 2651 | // parameter. |
| 2652 | bool LookupSymbolIfExists(String* str, String** symbol); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2653 | bool LookupTwoCharsSymbolIfExists(uint32_t c1, uint32_t c2, String** symbol); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2654 | |
| 2655 | // Casting. |
| 2656 | static inline SymbolTable* cast(Object* obj); |
| 2657 | |
| 2658 | private: |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2659 | MUST_USE_RESULT MaybeObject* LookupKey(HashTableKey* key, Object** s); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2660 | |
| 2661 | DISALLOW_IMPLICIT_CONSTRUCTORS(SymbolTable); |
| 2662 | }; |
| 2663 | |
| 2664 | |
| 2665 | class MapCacheShape { |
| 2666 | public: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2667 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2668 | return key->IsMatch(value); |
| 2669 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2670 | static inline uint32_t Hash(HashTableKey* key) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2671 | return key->Hash(); |
| 2672 | } |
| 2673 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2674 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2675 | return key->HashForObject(object); |
| 2676 | } |
| 2677 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2678 | MUST_USE_RESULT static inline MaybeObject* AsObject(HashTableKey* key) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2679 | return key->AsObject(); |
| 2680 | } |
| 2681 | |
| 2682 | static const int kPrefixSize = 0; |
| 2683 | static const int kEntrySize = 2; |
| 2684 | }; |
| 2685 | |
| 2686 | |
| 2687 | // MapCache. |
| 2688 | // |
| 2689 | // Maps keys that are a fixed array of symbols to a map. |
| 2690 | // Used for canonicalize maps for object literals. |
| 2691 | class MapCache: public HashTable<MapCacheShape, HashTableKey*> { |
| 2692 | public: |
| 2693 | // Find cached value for a string key, otherwise return null. |
| 2694 | Object* Lookup(FixedArray* key); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2695 | MUST_USE_RESULT MaybeObject* Put(FixedArray* key, Map* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2696 | static inline MapCache* cast(Object* obj); |
| 2697 | |
| 2698 | private: |
| 2699 | DISALLOW_IMPLICIT_CONSTRUCTORS(MapCache); |
| 2700 | }; |
| 2701 | |
| 2702 | |
| 2703 | template <typename Shape, typename Key> |
| 2704 | class Dictionary: public HashTable<Shape, Key> { |
| 2705 | public: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2706 | static inline Dictionary<Shape, Key>* cast(Object* obj) { |
| 2707 | return reinterpret_cast<Dictionary<Shape, Key>*>(obj); |
| 2708 | } |
| 2709 | |
| 2710 | // Returns the value at entry. |
| 2711 | Object* ValueAt(int entry) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2712 | return this->get(HashTable<Shape, Key>::EntryToIndex(entry)+1); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2713 | } |
| 2714 | |
| 2715 | // Set the value for entry. |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2716 | // Returns false if the put wasn't performed due to property being read only. |
| 2717 | // Returns true on successful put. |
| 2718 | bool ValueAtPut(int entry, Object* value) { |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 2719 | // Check that this value can actually be written. |
| 2720 | PropertyDetails details = DetailsAt(entry); |
| 2721 | // If a value has not been initilized we allow writing to it even if |
| 2722 | // it is read only (a declared const that has not been initialized). |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2723 | if (details.IsReadOnly() && !ValueAt(entry)->IsTheHole()) { |
| 2724 | return false; |
| 2725 | } |
| 2726 | this->set(HashTable<Shape, Key>::EntryToIndex(entry) + 1, value); |
| 2727 | return true; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2728 | } |
| 2729 | |
| 2730 | // Returns the property details for the property at entry. |
| 2731 | PropertyDetails DetailsAt(int entry) { |
| 2732 | ASSERT(entry >= 0); // Not found is -1, which is not caught by get(). |
| 2733 | return PropertyDetails( |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2734 | Smi::cast(this->get(HashTable<Shape, Key>::EntryToIndex(entry) + 2))); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2735 | } |
| 2736 | |
| 2737 | // Set the details for entry. |
| 2738 | void DetailsAtPut(int entry, PropertyDetails value) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2739 | this->set(HashTable<Shape, Key>::EntryToIndex(entry) + 2, value.AsSmi()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2740 | } |
| 2741 | |
| 2742 | // Sorting support |
| 2743 | void CopyValuesTo(FixedArray* elements); |
| 2744 | |
| 2745 | // Delete a property from the dictionary. |
| 2746 | Object* DeleteProperty(int entry, JSObject::DeleteMode mode); |
| 2747 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 2748 | // Attempt to shrink the dictionary after deletion of key. |
| 2749 | MUST_USE_RESULT MaybeObject* Shrink(Key key); |
| 2750 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2751 | // Returns the number of elements in the dictionary filtering out properties |
| 2752 | // with the specified attributes. |
| 2753 | int NumberOfElementsFilterAttributes(PropertyAttributes filter); |
| 2754 | |
| 2755 | // Returns the number of enumerable elements in the dictionary. |
| 2756 | int NumberOfEnumElements(); |
| 2757 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 2758 | enum SortMode { UNSORTED, SORTED }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2759 | // Copies keys to preallocated fixed array. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 2760 | void CopyKeysTo(FixedArray* storage, |
| 2761 | PropertyAttributes filter, |
| 2762 | SortMode sort_mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2763 | // Fill in details for properties into storage. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 2764 | void CopyKeysTo(FixedArray* storage, int index, SortMode sort_mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2765 | |
| 2766 | // Accessors for next enumeration index. |
| 2767 | void SetNextEnumerationIndex(int index) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2768 | this->fast_set(this, kNextEnumerationIndexIndex, Smi::FromInt(index)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2769 | } |
| 2770 | |
| 2771 | int NextEnumerationIndex() { |
| 2772 | return Smi::cast(FixedArray::get(kNextEnumerationIndexIndex))->value(); |
| 2773 | } |
| 2774 | |
| 2775 | // Returns a new array for dictionary usage. Might return Failure. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2776 | MUST_USE_RESULT static MaybeObject* Allocate(int at_least_space_for); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2777 | |
| 2778 | // Ensure enough space for n additional elements. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2779 | MUST_USE_RESULT MaybeObject* EnsureCapacity(int n, Key key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2780 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2781 | #ifdef OBJECT_PRINT |
| 2782 | inline void Print() { |
| 2783 | Print(stdout); |
| 2784 | } |
| 2785 | void Print(FILE* out); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2786 | #endif |
| 2787 | // Returns the key (slow). |
| 2788 | Object* SlowReverseLookup(Object* value); |
| 2789 | |
| 2790 | // Sets the entry to (key, value) pair. |
| 2791 | inline void SetEntry(int entry, |
| 2792 | Object* key, |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2793 | Object* value); |
| 2794 | inline void SetEntry(int entry, |
| 2795 | Object* key, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2796 | Object* value, |
| 2797 | PropertyDetails details); |
| 2798 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2799 | MUST_USE_RESULT MaybeObject* Add(Key key, |
| 2800 | Object* value, |
| 2801 | PropertyDetails details); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2802 | |
| 2803 | protected: |
| 2804 | // Generic at put operation. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2805 | MUST_USE_RESULT MaybeObject* AtPut(Key key, Object* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2806 | |
| 2807 | // Add entry to dictionary. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2808 | MUST_USE_RESULT MaybeObject* AddEntry(Key key, |
| 2809 | Object* value, |
| 2810 | PropertyDetails details, |
| 2811 | uint32_t hash); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2812 | |
| 2813 | // Generate new enumeration indices to avoid enumeration index overflow. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2814 | MUST_USE_RESULT MaybeObject* GenerateNewEnumerationIndices(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2815 | static const int kMaxNumberKeyIndex = |
| 2816 | HashTable<Shape, Key>::kPrefixStartIndex; |
| 2817 | static const int kNextEnumerationIndexIndex = kMaxNumberKeyIndex + 1; |
| 2818 | }; |
| 2819 | |
| 2820 | |
| 2821 | class StringDictionaryShape { |
| 2822 | public: |
| 2823 | static inline bool IsMatch(String* key, Object* other); |
| 2824 | static inline uint32_t Hash(String* key); |
| 2825 | static inline uint32_t HashForObject(String* key, Object* object); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2826 | MUST_USE_RESULT static inline MaybeObject* AsObject(String* key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2827 | static const int kPrefixSize = 2; |
| 2828 | static const int kEntrySize = 3; |
| 2829 | static const bool kIsEnumerable = true; |
| 2830 | }; |
| 2831 | |
| 2832 | |
| 2833 | class StringDictionary: public Dictionary<StringDictionaryShape, String*> { |
| 2834 | public: |
| 2835 | static inline StringDictionary* cast(Object* obj) { |
| 2836 | ASSERT(obj->IsDictionary()); |
| 2837 | return reinterpret_cast<StringDictionary*>(obj); |
| 2838 | } |
| 2839 | |
| 2840 | // Copies enumerable keys to preallocated fixed array. |
| 2841 | void CopyEnumKeysTo(FixedArray* storage, FixedArray* sort_array); |
| 2842 | |
| 2843 | // For transforming properties of a JSObject. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2844 | MUST_USE_RESULT MaybeObject* TransformPropertiesToFastFor( |
| 2845 | JSObject* obj, |
| 2846 | int unused_property_fields); |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 2847 | |
| 2848 | // Find entry for key otherwise return kNotFound. Optimzed version of |
| 2849 | // HashTable::FindEntry. |
| 2850 | int FindEntry(String* key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2851 | }; |
| 2852 | |
| 2853 | |
| 2854 | class NumberDictionaryShape { |
| 2855 | public: |
| 2856 | static inline bool IsMatch(uint32_t key, Object* other); |
| 2857 | static inline uint32_t Hash(uint32_t key); |
| 2858 | static inline uint32_t HashForObject(uint32_t key, Object* object); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2859 | MUST_USE_RESULT static inline MaybeObject* AsObject(uint32_t key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2860 | static const int kPrefixSize = 2; |
| 2861 | static const int kEntrySize = 3; |
| 2862 | static const bool kIsEnumerable = false; |
| 2863 | }; |
| 2864 | |
| 2865 | |
| 2866 | class NumberDictionary: public Dictionary<NumberDictionaryShape, uint32_t> { |
| 2867 | public: |
| 2868 | static NumberDictionary* cast(Object* obj) { |
| 2869 | ASSERT(obj->IsDictionary()); |
| 2870 | return reinterpret_cast<NumberDictionary*>(obj); |
| 2871 | } |
| 2872 | |
| 2873 | // Type specific at put (default NONE attributes is used when adding). |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2874 | MUST_USE_RESULT MaybeObject* AtNumberPut(uint32_t key, Object* value); |
| 2875 | MUST_USE_RESULT MaybeObject* AddNumberEntry(uint32_t key, |
| 2876 | Object* value, |
| 2877 | PropertyDetails details); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2878 | |
| 2879 | // Set an existing entry or add a new one if needed. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2880 | MUST_USE_RESULT MaybeObject* Set(uint32_t key, |
| 2881 | Object* value, |
| 2882 | PropertyDetails details); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2883 | |
| 2884 | void UpdateMaxNumberKey(uint32_t key); |
| 2885 | |
| 2886 | // If slow elements are required we will never go back to fast-case |
| 2887 | // for the elements kept in this dictionary. We require slow |
| 2888 | // elements if an element has been added at an index larger than |
| 2889 | // kRequiresSlowElementsLimit or set_requires_slow_elements() has been called |
| 2890 | // when defining a getter or setter with a number key. |
| 2891 | inline bool requires_slow_elements(); |
| 2892 | inline void set_requires_slow_elements(); |
| 2893 | |
| 2894 | // Get the value of the max number key that has been added to this |
| 2895 | // dictionary. max_number_key can only be called if |
| 2896 | // requires_slow_elements returns false. |
| 2897 | inline uint32_t max_number_key(); |
| 2898 | |
| 2899 | // Remove all entries were key is a number and (from <= key && key < to). |
| 2900 | void RemoveNumberEntries(uint32_t from, uint32_t to); |
| 2901 | |
| 2902 | // Bit masks. |
| 2903 | static const int kRequiresSlowElementsMask = 1; |
| 2904 | static const int kRequiresSlowElementsTagSize = 1; |
| 2905 | static const uint32_t kRequiresSlowElementsLimit = (1 << 29) - 1; |
| 2906 | }; |
| 2907 | |
| 2908 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2909 | // JSFunctionResultCache caches results of some JSFunction invocation. |
| 2910 | // It is a fixed array with fixed structure: |
| 2911 | // [0]: factory function |
| 2912 | // [1]: finger index |
| 2913 | // [2]: current cache size |
| 2914 | // [3]: dummy field. |
| 2915 | // The rest of array are key/value pairs. |
| 2916 | class JSFunctionResultCache: public FixedArray { |
| 2917 | public: |
| 2918 | static const int kFactoryIndex = 0; |
| 2919 | static const int kFingerIndex = kFactoryIndex + 1; |
| 2920 | static const int kCacheSizeIndex = kFingerIndex + 1; |
| 2921 | static const int kDummyIndex = kCacheSizeIndex + 1; |
| 2922 | static const int kEntriesIndex = kDummyIndex + 1; |
| 2923 | |
| 2924 | static const int kEntrySize = 2; // key + value |
| 2925 | |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 2926 | static const int kFactoryOffset = kHeaderSize; |
| 2927 | static const int kFingerOffset = kFactoryOffset + kPointerSize; |
| 2928 | static const int kCacheSizeOffset = kFingerOffset + kPointerSize; |
| 2929 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2930 | inline void MakeZeroSize(); |
| 2931 | inline void Clear(); |
| 2932 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 2933 | inline int size(); |
| 2934 | inline void set_size(int size); |
| 2935 | inline int finger_index(); |
| 2936 | inline void set_finger_index(int finger_index); |
| 2937 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2938 | // Casting |
| 2939 | static inline JSFunctionResultCache* cast(Object* obj); |
| 2940 | |
| 2941 | #ifdef DEBUG |
| 2942 | void JSFunctionResultCacheVerify(); |
| 2943 | #endif |
| 2944 | }; |
| 2945 | |
| 2946 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2947 | // The cache for maps used by normalized (dictionary mode) objects. |
| 2948 | // Such maps do not have property descriptors, so a typical program |
| 2949 | // needs very limited number of distinct normalized maps. |
| 2950 | class NormalizedMapCache: public FixedArray { |
| 2951 | public: |
| 2952 | static const int kEntries = 64; |
| 2953 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2954 | MUST_USE_RESULT MaybeObject* Get(JSObject* object, |
| 2955 | PropertyNormalizationMode mode); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2956 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2957 | void Clear(); |
| 2958 | |
| 2959 | // Casting |
| 2960 | static inline NormalizedMapCache* cast(Object* obj); |
| 2961 | |
| 2962 | #ifdef DEBUG |
| 2963 | void NormalizedMapCacheVerify(); |
| 2964 | #endif |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2965 | }; |
| 2966 | |
| 2967 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2968 | // ByteArray represents fixed sized byte arrays. Used by the outside world, |
| 2969 | // such as PCRE, and also by the memory allocator and garbage collector to |
| 2970 | // fill in free blocks in the heap. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2971 | class ByteArray: public HeapObject { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2972 | public: |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2973 | // [length]: length of the array. |
| 2974 | inline int length(); |
| 2975 | inline void set_length(int value); |
| 2976 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2977 | // Setter and getter. |
| 2978 | inline byte get(int index); |
| 2979 | inline void set(int index, byte value); |
| 2980 | |
| 2981 | // Treat contents as an int array. |
| 2982 | inline int get_int(int index); |
| 2983 | |
| 2984 | static int SizeFor(int length) { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2985 | return OBJECT_POINTER_ALIGN(kHeaderSize + length); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2986 | } |
| 2987 | // We use byte arrays for free blocks in the heap. Given a desired size in |
| 2988 | // bytes that is a multiple of the word size and big enough to hold a byte |
| 2989 | // array, this function returns the number of elements a byte array should |
| 2990 | // have. |
| 2991 | static int LengthFor(int size_in_bytes) { |
| 2992 | ASSERT(IsAligned(size_in_bytes, kPointerSize)); |
| 2993 | ASSERT(size_in_bytes >= kHeaderSize); |
| 2994 | return size_in_bytes - kHeaderSize; |
| 2995 | } |
| 2996 | |
| 2997 | // Returns data start address. |
| 2998 | inline Address GetDataStartAddress(); |
| 2999 | |
| 3000 | // Returns a pointer to the ByteArray object for a given data start address. |
| 3001 | static inline ByteArray* FromDataStartAddress(Address address); |
| 3002 | |
| 3003 | // Casting. |
| 3004 | static inline ByteArray* cast(Object* obj); |
| 3005 | |
| 3006 | // Dispatched behavior. |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 3007 | inline int ByteArraySize() { |
| 3008 | return SizeFor(this->length()); |
| 3009 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3010 | #ifdef OBJECT_PRINT |
| 3011 | inline void ByteArrayPrint() { |
| 3012 | ByteArrayPrint(stdout); |
| 3013 | } |
| 3014 | void ByteArrayPrint(FILE* out); |
| 3015 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3016 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3017 | void ByteArrayVerify(); |
| 3018 | #endif |
| 3019 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3020 | // Layout description. |
| 3021 | // Length is smi tagged when it is stored. |
| 3022 | static const int kLengthOffset = HeapObject::kHeaderSize; |
| 3023 | static const int kHeaderSize = kLengthOffset + kPointerSize; |
| 3024 | |
| 3025 | static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3026 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 3027 | // Maximal memory consumption for a single ByteArray. |
| 3028 | static const int kMaxSize = 512 * MB; |
| 3029 | // Maximal length of a single ByteArray. |
| 3030 | static const int kMaxLength = kMaxSize - kHeaderSize; |
| 3031 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3032 | private: |
| 3033 | DISALLOW_IMPLICIT_CONSTRUCTORS(ByteArray); |
| 3034 | }; |
| 3035 | |
| 3036 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3037 | // An ExternalArray represents a fixed-size array of primitive values |
| 3038 | // which live outside the JavaScript heap. Its subclasses are used to |
| 3039 | // implement the CanvasArray types being defined in the WebGL |
| 3040 | // specification. As of this writing the first public draft is not yet |
| 3041 | // available, but Khronos members can access the draft at: |
| 3042 | // https://cvs.khronos.org/svn/repos/3dweb/trunk/doc/spec/WebGL-spec.html |
| 3043 | // |
| 3044 | // The semantics of these arrays differ from CanvasPixelArray. |
| 3045 | // Out-of-range values passed to the setter are converted via a C |
| 3046 | // cast, not clamping. Out-of-range indices cause exceptions to be |
| 3047 | // raised rather than being silently ignored. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3048 | class ExternalArray: public HeapObject { |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3049 | public: |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3050 | // [length]: length of the array. |
| 3051 | inline int length(); |
| 3052 | inline void set_length(int value); |
| 3053 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3054 | // [external_pointer]: The pointer to the external memory area backing this |
| 3055 | // external array. |
| 3056 | DECL_ACCESSORS(external_pointer, void) // Pointer to the data store. |
| 3057 | |
| 3058 | // Casting. |
| 3059 | static inline ExternalArray* cast(Object* obj); |
| 3060 | |
| 3061 | // Maximal acceptable length for an external array. |
| 3062 | static const int kMaxLength = 0x3fffffff; |
| 3063 | |
| 3064 | // ExternalArray headers are not quadword aligned. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3065 | static const int kLengthOffset = HeapObject::kHeaderSize; |
| 3066 | static const int kExternalPointerOffset = |
| 3067 | POINTER_SIZE_ALIGN(kLengthOffset + kIntSize); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3068 | static const int kHeaderSize = kExternalPointerOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3069 | static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3070 | |
| 3071 | private: |
| 3072 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalArray); |
| 3073 | }; |
| 3074 | |
| 3075 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3076 | // A ExternalPixelArray represents a fixed-size byte array with special |
| 3077 | // semantics used for implementing the CanvasPixelArray object. Please see the |
| 3078 | // specification at: |
| 3079 | |
| 3080 | // http://www.whatwg.org/specs/web-apps/current-work/ |
| 3081 | // multipage/the-canvas-element.html#canvaspixelarray |
| 3082 | // In particular, write access clamps the value written to 0 or 255 if the |
| 3083 | // value written is outside this range. |
| 3084 | class ExternalPixelArray: public ExternalArray { |
| 3085 | public: |
| 3086 | inline uint8_t* external_pixel_pointer(); |
| 3087 | |
| 3088 | // Setter and getter. |
| 3089 | inline uint8_t get(int index); |
| 3090 | inline void set(int index, uint8_t value); |
| 3091 | |
| 3092 | // This accessor applies the correct conversion from Smi, HeapNumber and |
| 3093 | // undefined and clamps the converted value between 0 and 255. |
| 3094 | Object* SetValue(uint32_t index, Object* value); |
| 3095 | |
| 3096 | // Casting. |
| 3097 | static inline ExternalPixelArray* cast(Object* obj); |
| 3098 | |
| 3099 | #ifdef OBJECT_PRINT |
| 3100 | inline void ExternalPixelArrayPrint() { |
| 3101 | ExternalPixelArrayPrint(stdout); |
| 3102 | } |
| 3103 | void ExternalPixelArrayPrint(FILE* out); |
| 3104 | #endif |
| 3105 | #ifdef DEBUG |
| 3106 | void ExternalPixelArrayVerify(); |
| 3107 | #endif // DEBUG |
| 3108 | |
| 3109 | private: |
| 3110 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalPixelArray); |
| 3111 | }; |
| 3112 | |
| 3113 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3114 | class ExternalByteArray: public ExternalArray { |
| 3115 | public: |
| 3116 | // Setter and getter. |
| 3117 | inline int8_t get(int index); |
| 3118 | inline void set(int index, int8_t value); |
| 3119 | |
| 3120 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3121 | // and undefined. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 3122 | MaybeObject* SetValue(uint32_t index, Object* value); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3123 | |
| 3124 | // Casting. |
| 3125 | static inline ExternalByteArray* cast(Object* obj); |
| 3126 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3127 | #ifdef OBJECT_PRINT |
| 3128 | inline void ExternalByteArrayPrint() { |
| 3129 | ExternalByteArrayPrint(stdout); |
| 3130 | } |
| 3131 | void ExternalByteArrayPrint(FILE* out); |
| 3132 | #endif |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3133 | #ifdef DEBUG |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3134 | void ExternalByteArrayVerify(); |
| 3135 | #endif // DEBUG |
| 3136 | |
| 3137 | private: |
| 3138 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalByteArray); |
| 3139 | }; |
| 3140 | |
| 3141 | |
| 3142 | class ExternalUnsignedByteArray: public ExternalArray { |
| 3143 | public: |
| 3144 | // Setter and getter. |
| 3145 | inline uint8_t get(int index); |
| 3146 | inline void set(int index, uint8_t value); |
| 3147 | |
| 3148 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3149 | // and undefined. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 3150 | MaybeObject* SetValue(uint32_t index, Object* value); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3151 | |
| 3152 | // Casting. |
| 3153 | static inline ExternalUnsignedByteArray* cast(Object* obj); |
| 3154 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3155 | #ifdef OBJECT_PRINT |
| 3156 | inline void ExternalUnsignedByteArrayPrint() { |
| 3157 | ExternalUnsignedByteArrayPrint(stdout); |
| 3158 | } |
| 3159 | void ExternalUnsignedByteArrayPrint(FILE* out); |
| 3160 | #endif |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3161 | #ifdef DEBUG |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3162 | void ExternalUnsignedByteArrayVerify(); |
| 3163 | #endif // DEBUG |
| 3164 | |
| 3165 | private: |
| 3166 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedByteArray); |
| 3167 | }; |
| 3168 | |
| 3169 | |
| 3170 | class ExternalShortArray: public ExternalArray { |
| 3171 | public: |
| 3172 | // Setter and getter. |
| 3173 | inline int16_t get(int index); |
| 3174 | inline void set(int index, int16_t value); |
| 3175 | |
| 3176 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3177 | // and undefined. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 3178 | MaybeObject* SetValue(uint32_t index, Object* value); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3179 | |
| 3180 | // Casting. |
| 3181 | static inline ExternalShortArray* cast(Object* obj); |
| 3182 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3183 | #ifdef OBJECT_PRINT |
| 3184 | inline void ExternalShortArrayPrint() { |
| 3185 | ExternalShortArrayPrint(stdout); |
| 3186 | } |
| 3187 | void ExternalShortArrayPrint(FILE* out); |
| 3188 | #endif |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3189 | #ifdef DEBUG |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3190 | void ExternalShortArrayVerify(); |
| 3191 | #endif // DEBUG |
| 3192 | |
| 3193 | private: |
| 3194 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalShortArray); |
| 3195 | }; |
| 3196 | |
| 3197 | |
| 3198 | class ExternalUnsignedShortArray: public ExternalArray { |
| 3199 | public: |
| 3200 | // Setter and getter. |
| 3201 | inline uint16_t get(int index); |
| 3202 | inline void set(int index, uint16_t value); |
| 3203 | |
| 3204 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3205 | // and undefined. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 3206 | MaybeObject* SetValue(uint32_t index, Object* value); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3207 | |
| 3208 | // Casting. |
| 3209 | static inline ExternalUnsignedShortArray* cast(Object* obj); |
| 3210 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3211 | #ifdef OBJECT_PRINT |
| 3212 | inline void ExternalUnsignedShortArrayPrint() { |
| 3213 | ExternalUnsignedShortArrayPrint(stdout); |
| 3214 | } |
| 3215 | void ExternalUnsignedShortArrayPrint(FILE* out); |
| 3216 | #endif |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3217 | #ifdef DEBUG |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3218 | void ExternalUnsignedShortArrayVerify(); |
| 3219 | #endif // DEBUG |
| 3220 | |
| 3221 | private: |
| 3222 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedShortArray); |
| 3223 | }; |
| 3224 | |
| 3225 | |
| 3226 | class ExternalIntArray: public ExternalArray { |
| 3227 | public: |
| 3228 | // Setter and getter. |
| 3229 | inline int32_t get(int index); |
| 3230 | inline void set(int index, int32_t value); |
| 3231 | |
| 3232 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3233 | // and undefined. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 3234 | MaybeObject* SetValue(uint32_t index, Object* value); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3235 | |
| 3236 | // Casting. |
| 3237 | static inline ExternalIntArray* cast(Object* obj); |
| 3238 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3239 | #ifdef OBJECT_PRINT |
| 3240 | inline void ExternalIntArrayPrint() { |
| 3241 | ExternalIntArrayPrint(stdout); |
| 3242 | } |
| 3243 | void ExternalIntArrayPrint(FILE* out); |
| 3244 | #endif |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3245 | #ifdef DEBUG |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3246 | void ExternalIntArrayVerify(); |
| 3247 | #endif // DEBUG |
| 3248 | |
| 3249 | private: |
| 3250 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalIntArray); |
| 3251 | }; |
| 3252 | |
| 3253 | |
| 3254 | class ExternalUnsignedIntArray: public ExternalArray { |
| 3255 | public: |
| 3256 | // Setter and getter. |
| 3257 | inline uint32_t get(int index); |
| 3258 | inline void set(int index, uint32_t value); |
| 3259 | |
| 3260 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3261 | // and undefined. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 3262 | MaybeObject* SetValue(uint32_t index, Object* value); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3263 | |
| 3264 | // Casting. |
| 3265 | static inline ExternalUnsignedIntArray* cast(Object* obj); |
| 3266 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3267 | #ifdef OBJECT_PRINT |
| 3268 | inline void ExternalUnsignedIntArrayPrint() { |
| 3269 | ExternalUnsignedIntArrayPrint(stdout); |
| 3270 | } |
| 3271 | void ExternalUnsignedIntArrayPrint(FILE* out); |
| 3272 | #endif |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3273 | #ifdef DEBUG |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3274 | void ExternalUnsignedIntArrayVerify(); |
| 3275 | #endif // DEBUG |
| 3276 | |
| 3277 | private: |
| 3278 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedIntArray); |
| 3279 | }; |
| 3280 | |
| 3281 | |
| 3282 | class ExternalFloatArray: public ExternalArray { |
| 3283 | public: |
| 3284 | // Setter and getter. |
| 3285 | inline float get(int index); |
| 3286 | inline void set(int index, float value); |
| 3287 | |
| 3288 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3289 | // and undefined. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 3290 | MaybeObject* SetValue(uint32_t index, Object* value); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3291 | |
| 3292 | // Casting. |
| 3293 | static inline ExternalFloatArray* cast(Object* obj); |
| 3294 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3295 | #ifdef OBJECT_PRINT |
| 3296 | inline void ExternalFloatArrayPrint() { |
| 3297 | ExternalFloatArrayPrint(stdout); |
| 3298 | } |
| 3299 | void ExternalFloatArrayPrint(FILE* out); |
| 3300 | #endif |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3301 | #ifdef DEBUG |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3302 | void ExternalFloatArrayVerify(); |
| 3303 | #endif // DEBUG |
| 3304 | |
| 3305 | private: |
| 3306 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalFloatArray); |
| 3307 | }; |
| 3308 | |
| 3309 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3310 | class ExternalDoubleArray: public ExternalArray { |
| 3311 | public: |
| 3312 | // Setter and getter. |
| 3313 | inline double get(int index); |
| 3314 | inline void set(int index, double value); |
| 3315 | |
| 3316 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3317 | // and undefined. |
| 3318 | MaybeObject* SetValue(uint32_t index, Object* value); |
| 3319 | |
| 3320 | // Casting. |
| 3321 | static inline ExternalDoubleArray* cast(Object* obj); |
| 3322 | |
| 3323 | #ifdef OBJECT_PRINT |
| 3324 | inline void ExternalDoubleArrayPrint() { |
| 3325 | ExternalDoubleArrayPrint(stdout); |
| 3326 | } |
| 3327 | void ExternalDoubleArrayPrint(FILE* out); |
| 3328 | #endif // OBJECT_PRINT |
| 3329 | #ifdef DEBUG |
| 3330 | void ExternalDoubleArrayVerify(); |
| 3331 | #endif // DEBUG |
| 3332 | |
| 3333 | private: |
| 3334 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalDoubleArray); |
| 3335 | }; |
| 3336 | |
| 3337 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3338 | // DeoptimizationInputData is a fixed array used to hold the deoptimization |
| 3339 | // data for code generated by the Hydrogen/Lithium compiler. It also |
| 3340 | // contains information about functions that were inlined. If N different |
| 3341 | // functions were inlined then first N elements of the literal array will |
| 3342 | // contain these functions. |
| 3343 | // |
| 3344 | // It can be empty. |
| 3345 | class DeoptimizationInputData: public FixedArray { |
| 3346 | public: |
| 3347 | // Layout description. Indices in the array. |
| 3348 | static const int kTranslationByteArrayIndex = 0; |
| 3349 | static const int kInlinedFunctionCountIndex = 1; |
| 3350 | static const int kLiteralArrayIndex = 2; |
| 3351 | static const int kOsrAstIdIndex = 3; |
| 3352 | static const int kOsrPcOffsetIndex = 4; |
| 3353 | static const int kFirstDeoptEntryIndex = 5; |
| 3354 | |
| 3355 | // Offsets of deopt entry elements relative to the start of the entry. |
| 3356 | static const int kAstIdOffset = 0; |
| 3357 | static const int kTranslationIndexOffset = 1; |
| 3358 | static const int kArgumentsStackHeightOffset = 2; |
| 3359 | static const int kDeoptEntrySize = 3; |
| 3360 | |
| 3361 | // Simple element accessors. |
| 3362 | #define DEFINE_ELEMENT_ACCESSORS(name, type) \ |
| 3363 | type* name() { \ |
| 3364 | return type::cast(get(k##name##Index)); \ |
| 3365 | } \ |
| 3366 | void Set##name(type* value) { \ |
| 3367 | set(k##name##Index, value); \ |
| 3368 | } |
| 3369 | |
| 3370 | DEFINE_ELEMENT_ACCESSORS(TranslationByteArray, ByteArray) |
| 3371 | DEFINE_ELEMENT_ACCESSORS(InlinedFunctionCount, Smi) |
| 3372 | DEFINE_ELEMENT_ACCESSORS(LiteralArray, FixedArray) |
| 3373 | DEFINE_ELEMENT_ACCESSORS(OsrAstId, Smi) |
| 3374 | DEFINE_ELEMENT_ACCESSORS(OsrPcOffset, Smi) |
| 3375 | |
| 3376 | // Unchecked accessor to be used during GC. |
| 3377 | FixedArray* UncheckedLiteralArray() { |
| 3378 | return reinterpret_cast<FixedArray*>(get(kLiteralArrayIndex)); |
| 3379 | } |
| 3380 | |
| 3381 | #undef DEFINE_ELEMENT_ACCESSORS |
| 3382 | |
| 3383 | // Accessors for elements of the ith deoptimization entry. |
| 3384 | #define DEFINE_ENTRY_ACCESSORS(name, type) \ |
| 3385 | type* name(int i) { \ |
| 3386 | return type::cast(get(IndexForEntry(i) + k##name##Offset)); \ |
| 3387 | } \ |
| 3388 | void Set##name(int i, type* value) { \ |
| 3389 | set(IndexForEntry(i) + k##name##Offset, value); \ |
| 3390 | } |
| 3391 | |
| 3392 | DEFINE_ENTRY_ACCESSORS(AstId, Smi) |
| 3393 | DEFINE_ENTRY_ACCESSORS(TranslationIndex, Smi) |
| 3394 | DEFINE_ENTRY_ACCESSORS(ArgumentsStackHeight, Smi) |
| 3395 | |
| 3396 | #undef DEFINE_ENTRY_ACCESSORS |
| 3397 | |
| 3398 | int DeoptCount() { |
| 3399 | return (length() - kFirstDeoptEntryIndex) / kDeoptEntrySize; |
| 3400 | } |
| 3401 | |
| 3402 | // Allocates a DeoptimizationInputData. |
| 3403 | MUST_USE_RESULT static MaybeObject* Allocate(int deopt_entry_count, |
| 3404 | PretenureFlag pretenure); |
| 3405 | |
| 3406 | // Casting. |
| 3407 | static inline DeoptimizationInputData* cast(Object* obj); |
| 3408 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 3409 | #ifdef ENABLE_DISASSEMBLER |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3410 | void DeoptimizationInputDataPrint(FILE* out); |
| 3411 | #endif |
| 3412 | |
| 3413 | private: |
| 3414 | static int IndexForEntry(int i) { |
| 3415 | return kFirstDeoptEntryIndex + (i * kDeoptEntrySize); |
| 3416 | } |
| 3417 | |
| 3418 | static int LengthFor(int entry_count) { |
| 3419 | return IndexForEntry(entry_count); |
| 3420 | } |
| 3421 | }; |
| 3422 | |
| 3423 | |
| 3424 | // DeoptimizationOutputData is a fixed array used to hold the deoptimization |
| 3425 | // data for code generated by the full compiler. |
| 3426 | // The format of the these objects is |
| 3427 | // [i * 2]: Ast ID for ith deoptimization. |
| 3428 | // [i * 2 + 1]: PC and state of ith deoptimization |
| 3429 | class DeoptimizationOutputData: public FixedArray { |
| 3430 | public: |
| 3431 | int DeoptPoints() { return length() / 2; } |
| 3432 | Smi* AstId(int index) { return Smi::cast(get(index * 2)); } |
| 3433 | void SetAstId(int index, Smi* id) { set(index * 2, id); } |
| 3434 | Smi* PcAndState(int index) { return Smi::cast(get(1 + index * 2)); } |
| 3435 | void SetPcAndState(int index, Smi* offset) { set(1 + index * 2, offset); } |
| 3436 | |
| 3437 | static int LengthOfFixedArray(int deopt_points) { |
| 3438 | return deopt_points * 2; |
| 3439 | } |
| 3440 | |
| 3441 | // Allocates a DeoptimizationOutputData. |
| 3442 | MUST_USE_RESULT static MaybeObject* Allocate(int number_of_deopt_points, |
| 3443 | PretenureFlag pretenure); |
| 3444 | |
| 3445 | // Casting. |
| 3446 | static inline DeoptimizationOutputData* cast(Object* obj); |
| 3447 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 3448 | #if defined(OBJECT_PRINT) || defined(ENABLE_DISASSEMBLER) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3449 | void DeoptimizationOutputDataPrint(FILE* out); |
| 3450 | #endif |
| 3451 | }; |
| 3452 | |
| 3453 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 3454 | class SafepointEntry; |
| 3455 | |
| 3456 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3457 | // Code describes objects with on-the-fly generated machine code. |
| 3458 | class Code: public HeapObject { |
| 3459 | public: |
| 3460 | // Opaque data type for encapsulating code flags like kind, inline |
| 3461 | // cache state, and arguments count. |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 3462 | // FLAGS_MIN_VALUE and FLAGS_MAX_VALUE are specified to ensure that |
| 3463 | // enumeration type has correct value range (see Issue 830 for more details). |
| 3464 | enum Flags { |
| 3465 | FLAGS_MIN_VALUE = kMinInt, |
| 3466 | FLAGS_MAX_VALUE = kMaxInt |
| 3467 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3468 | |
| 3469 | enum Kind { |
| 3470 | FUNCTION, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3471 | OPTIMIZED_FUNCTION, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3472 | STUB, |
| 3473 | BUILTIN, |
| 3474 | LOAD_IC, |
| 3475 | KEYED_LOAD_IC, |
| 3476 | CALL_IC, |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3477 | KEYED_CALL_IC, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3478 | STORE_IC, |
| 3479 | KEYED_STORE_IC, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3480 | UNARY_OP_IC, |
| 3481 | BINARY_OP_IC, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3482 | COMPARE_IC, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3483 | // 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] | 3484 | // Flags. |
| 3485 | |
| 3486 | // Pseudo-kinds. |
| 3487 | REGEXP = BUILTIN, |
| 3488 | FIRST_IC_KIND = LOAD_IC, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3489 | LAST_IC_KIND = COMPARE_IC |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3490 | }; |
| 3491 | |
| 3492 | enum { |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 3493 | NUMBER_OF_KINDS = LAST_IC_KIND + 1 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3494 | }; |
| 3495 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 3496 | typedef int ExtraICState; |
| 3497 | |
| 3498 | static const ExtraICState kNoExtraICState = 0; |
| 3499 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3500 | #ifdef ENABLE_DISASSEMBLER |
| 3501 | // Printing |
| 3502 | static const char* Kind2String(Kind kind); |
| 3503 | static const char* ICState2String(InlineCacheState state); |
| 3504 | static const char* PropertyType2String(PropertyType type); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3505 | static void PrintExtraICState(FILE* out, Kind kind, ExtraICState extra); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3506 | inline void Disassemble(const char* name) { |
| 3507 | Disassemble(name, stdout); |
| 3508 | } |
| 3509 | void Disassemble(const char* name, FILE* out); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3510 | #endif // ENABLE_DISASSEMBLER |
| 3511 | |
| 3512 | // [instruction_size]: Size of the native instructions |
| 3513 | inline int instruction_size(); |
| 3514 | inline void set_instruction_size(int value); |
| 3515 | |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 3516 | // [relocation_info]: Code relocation information |
| 3517 | DECL_ACCESSORS(relocation_info, ByteArray) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3518 | void InvalidateRelocation(); |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 3519 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3520 | // [deoptimization_data]: Array containing data for deopt. |
| 3521 | DECL_ACCESSORS(deoptimization_data, FixedArray) |
| 3522 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3523 | // [code_flushing_candidate]: Field only used during garbage |
| 3524 | // collection to hold code flushing candidates. The contents of this |
| 3525 | // field does not have to be traced during garbage collection since |
| 3526 | // it is only used by the garbage collector itself. |
| 3527 | DECL_ACCESSORS(next_code_flushing_candidate, Object) |
| 3528 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3529 | // Unchecked accessors to be used during GC. |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 3530 | inline ByteArray* unchecked_relocation_info(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3531 | inline FixedArray* unchecked_deoptimization_data(); |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 3532 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3533 | inline int relocation_size(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3534 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3535 | // [flags]: Various code flags. |
| 3536 | inline Flags flags(); |
| 3537 | inline void set_flags(Flags flags); |
| 3538 | |
| 3539 | // [flags]: Access to specific code flags. |
| 3540 | inline Kind kind(); |
| 3541 | inline InlineCacheState ic_state(); // Only valid for IC stubs. |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 3542 | inline ExtraICState extra_ic_state(); // Only valid for IC stubs. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3543 | inline InLoopFlag ic_in_loop(); // Only valid for IC stubs. |
| 3544 | inline PropertyType type(); // Only valid for monomorphic IC stubs. |
| 3545 | inline int arguments_count(); // Only valid for call IC stubs. |
| 3546 | |
| 3547 | // Testers for IC stub kinds. |
| 3548 | inline bool is_inline_cache_stub(); |
| 3549 | inline bool is_load_stub() { return kind() == LOAD_IC; } |
| 3550 | inline bool is_keyed_load_stub() { return kind() == KEYED_LOAD_IC; } |
| 3551 | inline bool is_store_stub() { return kind() == STORE_IC; } |
| 3552 | inline bool is_keyed_store_stub() { return kind() == KEYED_STORE_IC; } |
| 3553 | inline bool is_call_stub() { return kind() == CALL_IC; } |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3554 | inline bool is_keyed_call_stub() { return kind() == KEYED_CALL_IC; } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3555 | inline bool is_unary_op_stub() { |
| 3556 | return kind() == UNARY_OP_IC; |
| 3557 | } |
| 3558 | inline bool is_binary_op_stub() { |
| 3559 | return kind() == BINARY_OP_IC; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3560 | } |
| 3561 | inline bool is_compare_ic_stub() { return kind() == COMPARE_IC; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3562 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3563 | // [major_key]: For kind STUB or BINARY_OP_IC, the major key. |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3564 | inline int major_key(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3565 | inline void set_major_key(int value); |
| 3566 | |
| 3567 | // [optimizable]: For FUNCTION kind, tells if it is optimizable. |
| 3568 | inline bool optimizable(); |
| 3569 | inline void set_optimizable(bool value); |
| 3570 | |
| 3571 | // [has_deoptimization_support]: For FUNCTION kind, tells if it has |
| 3572 | // deoptimization support. |
| 3573 | inline bool has_deoptimization_support(); |
| 3574 | inline void set_has_deoptimization_support(bool value); |
| 3575 | |
| 3576 | // [allow_osr_at_loop_nesting_level]: For FUNCTION kind, tells for |
| 3577 | // how long the function has been marked for OSR and therefore which |
| 3578 | // level of loop nesting we are willing to do on-stack replacement |
| 3579 | // for. |
| 3580 | inline void set_allow_osr_at_loop_nesting_level(int level); |
| 3581 | inline int allow_osr_at_loop_nesting_level(); |
| 3582 | |
| 3583 | // [stack_slots]: For kind OPTIMIZED_FUNCTION, the number of stack slots |
| 3584 | // reserved in the code prologue. |
| 3585 | inline unsigned stack_slots(); |
| 3586 | inline void set_stack_slots(unsigned slots); |
| 3587 | |
| 3588 | // [safepoint_table_start]: For kind OPTIMIZED_CODE, the offset in |
| 3589 | // the instruction stream where the safepoint table starts. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3590 | inline unsigned safepoint_table_offset(); |
| 3591 | inline void set_safepoint_table_offset(unsigned offset); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3592 | |
| 3593 | // [stack_check_table_start]: For kind FUNCTION, the offset in the |
| 3594 | // instruction stream where the stack check table starts. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3595 | inline unsigned stack_check_table_offset(); |
| 3596 | inline void set_stack_check_table_offset(unsigned offset); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3597 | |
| 3598 | // [check type]: For kind CALL_IC, tells how to check if the |
| 3599 | // receiver is valid for the given call. |
| 3600 | inline CheckType check_type(); |
| 3601 | inline void set_check_type(CheckType value); |
| 3602 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3603 | // [type-recording unary op type]: For all UNARY_OP_IC. |
| 3604 | inline byte unary_op_type(); |
| 3605 | inline void set_unary_op_type(byte value); |
| 3606 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3607 | // [type-recording binary op type]: For all TYPE_RECORDING_BINARY_OP_IC. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3608 | inline byte binary_op_type(); |
| 3609 | inline void set_binary_op_type(byte value); |
| 3610 | inline byte binary_op_result_type(); |
| 3611 | inline void set_binary_op_result_type(byte value); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3612 | |
| 3613 | // [compare state]: For kind compare IC stubs, tells what state the |
| 3614 | // stub is in. |
| 3615 | inline byte compare_state(); |
| 3616 | inline void set_compare_state(byte value); |
| 3617 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 3618 | // Get the safepoint entry for the given pc. |
| 3619 | SafepointEntry GetSafepointEntry(Address pc); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3620 | |
| 3621 | // Mark this code object as not having a stack check table. Assumes kind |
| 3622 | // is FUNCTION. |
| 3623 | void SetNoStackCheckTable(); |
| 3624 | |
| 3625 | // Find the first map in an IC stub. |
| 3626 | Map* FindFirstMap(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3627 | |
| 3628 | // Flags operations. |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 3629 | static inline Flags ComputeFlags( |
| 3630 | Kind kind, |
| 3631 | InLoopFlag in_loop = NOT_IN_LOOP, |
| 3632 | InlineCacheState ic_state = UNINITIALIZED, |
| 3633 | ExtraICState extra_ic_state = kNoExtraICState, |
| 3634 | PropertyType type = NORMAL, |
| 3635 | int argc = -1, |
| 3636 | InlineCacheHolderFlag holder = OWN_MAP); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3637 | |
| 3638 | static inline Flags ComputeMonomorphicFlags( |
| 3639 | Kind kind, |
| 3640 | PropertyType type, |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 3641 | ExtraICState extra_ic_state = kNoExtraICState, |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 3642 | InlineCacheHolderFlag holder = OWN_MAP, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3643 | InLoopFlag in_loop = NOT_IN_LOOP, |
| 3644 | int argc = -1); |
| 3645 | |
| 3646 | static inline Kind ExtractKindFromFlags(Flags flags); |
| 3647 | static inline InlineCacheState ExtractICStateFromFlags(Flags flags); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 3648 | static inline ExtraICState ExtractExtraICStateFromFlags(Flags flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3649 | static inline InLoopFlag ExtractICInLoopFromFlags(Flags flags); |
| 3650 | static inline PropertyType ExtractTypeFromFlags(Flags flags); |
| 3651 | static inline int ExtractArgumentsCountFromFlags(Flags flags); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 3652 | static inline InlineCacheHolderFlag ExtractCacheHolderFromFlags(Flags flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3653 | static inline Flags RemoveTypeFromFlags(Flags flags); |
| 3654 | |
| 3655 | // Convert a target address into a code object. |
| 3656 | static inline Code* GetCodeFromTargetAddress(Address address); |
| 3657 | |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 3658 | // Convert an entry address into an object. |
| 3659 | static inline Object* GetObjectFromEntryAddress(Address location_of_address); |
| 3660 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3661 | // Returns the address of the first instruction. |
| 3662 | inline byte* instruction_start(); |
| 3663 | |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 3664 | // Returns the address right after the last instruction. |
| 3665 | inline byte* instruction_end(); |
| 3666 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3667 | // Returns the size of the instructions, padding, and relocation information. |
| 3668 | inline int body_size(); |
| 3669 | |
| 3670 | // Returns the address of the first relocation info (read backwards!). |
| 3671 | inline byte* relocation_start(); |
| 3672 | |
| 3673 | // Code entry point. |
| 3674 | inline byte* entry(); |
| 3675 | |
| 3676 | // Returns true if pc is inside this object's instructions. |
| 3677 | inline bool contains(byte* pc); |
| 3678 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3679 | // Relocate the code by delta bytes. Called to signal that this code |
| 3680 | // object has been moved by delta bytes. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 3681 | void Relocate(intptr_t delta); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3682 | |
| 3683 | // Migrate code described by desc. |
| 3684 | void CopyFrom(const CodeDesc& desc); |
| 3685 | |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 3686 | // Returns the object size for a given body (used for allocation). |
| 3687 | static int SizeFor(int body_size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3688 | ASSERT_SIZE_TAG_ALIGNED(body_size); |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 3689 | return RoundUp(kHeaderSize + body_size, kCodeAlignment); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3690 | } |
| 3691 | |
| 3692 | // Calculate the size of the code object to report for log events. This takes |
| 3693 | // the layout of the code object into account. |
| 3694 | int ExecutableSize() { |
| 3695 | // Check that the assumptions about the layout of the code object holds. |
| 3696 | ASSERT_EQ(static_cast<int>(instruction_start() - address()), |
| 3697 | Code::kHeaderSize); |
| 3698 | return instruction_size() + Code::kHeaderSize; |
| 3699 | } |
| 3700 | |
| 3701 | // Locating source position. |
| 3702 | int SourcePosition(Address pc); |
| 3703 | int SourceStatementPosition(Address pc); |
| 3704 | |
| 3705 | // Casting. |
| 3706 | static inline Code* cast(Object* obj); |
| 3707 | |
| 3708 | // Dispatched behavior. |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 3709 | int CodeSize() { return SizeFor(body_size()); } |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 3710 | inline void CodeIterateBody(ObjectVisitor* v); |
| 3711 | |
| 3712 | template<typename StaticVisitor> |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3713 | inline void CodeIterateBody(Heap* heap); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3714 | #ifdef OBJECT_PRINT |
| 3715 | inline void CodePrint() { |
| 3716 | CodePrint(stdout); |
| 3717 | } |
| 3718 | void CodePrint(FILE* out); |
| 3719 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3720 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3721 | void CodeVerify(); |
| 3722 | #endif |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3723 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3724 | // Returns the isolate/heap this code object belongs to. |
| 3725 | inline Isolate* isolate(); |
| 3726 | inline Heap* heap(); |
| 3727 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3728 | // Max loop nesting marker used to postpose OSR. We don't take loop |
| 3729 | // nesting that is deeper than 5 levels into account. |
| 3730 | static const int kMaxLoopNestingMarker = 6; |
| 3731 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3732 | // Layout description. |
| 3733 | static const int kInstructionSizeOffset = HeapObject::kHeaderSize; |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 3734 | static const int kRelocationInfoOffset = kInstructionSizeOffset + kIntSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3735 | static const int kDeoptimizationDataOffset = |
| 3736 | kRelocationInfoOffset + kPointerSize; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3737 | static const int kNextCodeFlushingCandidateOffset = |
| 3738 | kDeoptimizationDataOffset + kPointerSize; |
| 3739 | static const int kFlagsOffset = |
| 3740 | kNextCodeFlushingCandidateOffset + kPointerSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3741 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3742 | static const int kKindSpecificFlagsOffset = kFlagsOffset + kIntSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3743 | static const int kKindSpecificFlagsSize = 2 * kIntSize; |
| 3744 | |
| 3745 | static const int kHeaderPaddingStart = kKindSpecificFlagsOffset + |
| 3746 | kKindSpecificFlagsSize; |
| 3747 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3748 | // Add padding to align the instruction start following right after |
| 3749 | // the Code object header. |
| 3750 | static const int kHeaderSize = |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3751 | (kHeaderPaddingStart + kCodeAlignmentMask) & ~kCodeAlignmentMask; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3752 | |
| 3753 | // Byte offsets within kKindSpecificFlagsOffset. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3754 | static const int kStubMajorKeyOffset = kKindSpecificFlagsOffset; |
| 3755 | static const int kOptimizableOffset = kKindSpecificFlagsOffset; |
| 3756 | static const int kStackSlotsOffset = kKindSpecificFlagsOffset; |
| 3757 | static const int kCheckTypeOffset = kKindSpecificFlagsOffset; |
| 3758 | |
| 3759 | static const int kCompareStateOffset = kStubMajorKeyOffset + 1; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3760 | static const int kUnaryOpTypeOffset = kStubMajorKeyOffset + 1; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3761 | static const int kBinaryOpTypeOffset = kStubMajorKeyOffset + 1; |
| 3762 | static const int kHasDeoptimizationSupportOffset = kOptimizableOffset + 1; |
| 3763 | |
| 3764 | static const int kBinaryOpReturnTypeOffset = kBinaryOpTypeOffset + 1; |
| 3765 | static const int kAllowOSRAtLoopNestingLevelOffset = |
| 3766 | kHasDeoptimizationSupportOffset + 1; |
| 3767 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3768 | static const int kSafepointTableOffsetOffset = kStackSlotsOffset + kIntSize; |
| 3769 | static const int kStackCheckTableOffsetOffset = kStackSlotsOffset + kIntSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3770 | |
| 3771 | // Flags layout. |
| 3772 | static const int kFlagsICStateShift = 0; |
| 3773 | static const int kFlagsICInLoopShift = 3; |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 3774 | static const int kFlagsTypeShift = 4; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3775 | static const int kFlagsKindShift = 8; |
| 3776 | static const int kFlagsICHolderShift = 12; |
| 3777 | static const int kFlagsExtraICStateShift = 13; |
| 3778 | static const int kFlagsArgumentsCountShift = 15; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3779 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3780 | static const int kFlagsICStateMask = 0x00000007; // 00000000111 |
| 3781 | static const int kFlagsICInLoopMask = 0x00000008; // 00000001000 |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3782 | static const int kFlagsTypeMask = 0x000000F0; // 00001110000 |
| 3783 | static const int kFlagsKindMask = 0x00000F00; // 11110000000 |
| 3784 | static const int kFlagsCacheInPrototypeMapMask = 0x00001000; |
| 3785 | static const int kFlagsExtraICStateMask = 0x00006000; |
| 3786 | static const int kFlagsArgumentsCountMask = 0xFFFF8000; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3787 | |
| 3788 | static const int kFlagsNotUsedInLookup = |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 3789 | (kFlagsICInLoopMask | kFlagsTypeMask | kFlagsCacheInPrototypeMapMask); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3790 | |
| 3791 | private: |
| 3792 | DISALLOW_IMPLICIT_CONSTRUCTORS(Code); |
| 3793 | }; |
| 3794 | |
| 3795 | |
| 3796 | // All heap objects have a Map that describes their structure. |
| 3797 | // A Map contains information about: |
| 3798 | // - Size information about the object |
| 3799 | // - How to iterate over an object (for garbage collection) |
| 3800 | class Map: public HeapObject { |
| 3801 | public: |
| 3802 | // Instance size. |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 3803 | // Size in bytes or kVariableSizeSentinel if instances do not have |
| 3804 | // a fixed size. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3805 | inline int instance_size(); |
| 3806 | inline void set_instance_size(int value); |
| 3807 | |
| 3808 | // Count of properties allocated in the object. |
| 3809 | inline int inobject_properties(); |
| 3810 | inline void set_inobject_properties(int value); |
| 3811 | |
| 3812 | // Count of property fields pre-allocated in the object when first allocated. |
| 3813 | inline int pre_allocated_property_fields(); |
| 3814 | inline void set_pre_allocated_property_fields(int value); |
| 3815 | |
| 3816 | // Instance type. |
| 3817 | inline InstanceType instance_type(); |
| 3818 | inline void set_instance_type(InstanceType value); |
| 3819 | |
| 3820 | // Tells how many unused property fields are available in the |
| 3821 | // instance (only used for JSObject in fast mode). |
| 3822 | inline int unused_property_fields(); |
| 3823 | inline void set_unused_property_fields(int value); |
| 3824 | |
| 3825 | // Bit field. |
| 3826 | inline byte bit_field(); |
| 3827 | inline void set_bit_field(byte value); |
| 3828 | |
| 3829 | // Bit field 2. |
| 3830 | inline byte bit_field2(); |
| 3831 | inline void set_bit_field2(byte value); |
| 3832 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3833 | // Bit field 3. |
| 3834 | // TODO(1399): It should be possible to make room for bit_field3 in the map |
| 3835 | // without overloading the instance descriptors field (and storing it in the |
| 3836 | // DescriptorArray when the map has one). |
| 3837 | inline int bit_field3(); |
| 3838 | inline void set_bit_field3(int value); |
| 3839 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3840 | // Tells whether the object in the prototype property will be used |
| 3841 | // for instances created from this function. If the prototype |
| 3842 | // property is set to a value that is not a JSObject, the prototype |
| 3843 | // property will not be used to create instances of the function. |
| 3844 | // See ECMA-262, 13.2.2. |
| 3845 | inline void set_non_instance_prototype(bool value); |
| 3846 | inline bool has_non_instance_prototype(); |
| 3847 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3848 | // Tells whether function has special prototype property. If not, prototype |
| 3849 | // property will not be created when accessed (will return undefined), |
| 3850 | // and construction from this function will not be allowed. |
| 3851 | inline void set_function_with_prototype(bool value); |
| 3852 | inline bool function_with_prototype(); |
| 3853 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3854 | // Tells whether the instance with this map should be ignored by the |
| 3855 | // __proto__ accessor. |
| 3856 | inline void set_is_hidden_prototype() { |
| 3857 | set_bit_field(bit_field() | (1 << kIsHiddenPrototype)); |
| 3858 | } |
| 3859 | |
| 3860 | inline bool is_hidden_prototype() { |
| 3861 | return ((1 << kIsHiddenPrototype) & bit_field()) != 0; |
| 3862 | } |
| 3863 | |
| 3864 | // Records and queries whether the instance has a named interceptor. |
| 3865 | inline void set_has_named_interceptor() { |
| 3866 | set_bit_field(bit_field() | (1 << kHasNamedInterceptor)); |
| 3867 | } |
| 3868 | |
| 3869 | inline bool has_named_interceptor() { |
| 3870 | return ((1 << kHasNamedInterceptor) & bit_field()) != 0; |
| 3871 | } |
| 3872 | |
| 3873 | // Records and queries whether the instance has an indexed interceptor. |
| 3874 | inline void set_has_indexed_interceptor() { |
| 3875 | set_bit_field(bit_field() | (1 << kHasIndexedInterceptor)); |
| 3876 | } |
| 3877 | |
| 3878 | inline bool has_indexed_interceptor() { |
| 3879 | return ((1 << kHasIndexedInterceptor) & bit_field()) != 0; |
| 3880 | } |
| 3881 | |
| 3882 | // Tells whether the instance is undetectable. |
| 3883 | // An undetectable object is a special class of JSObject: 'typeof' operator |
| 3884 | // returns undefined, ToBoolean returns false. Otherwise it behaves like |
| 3885 | // a normal JS object. It is useful for implementing undetectable |
| 3886 | // document.all in Firefox & Safari. |
| 3887 | // See https://bugzilla.mozilla.org/show_bug.cgi?id=248549. |
| 3888 | inline void set_is_undetectable() { |
| 3889 | set_bit_field(bit_field() | (1 << kIsUndetectable)); |
| 3890 | } |
| 3891 | |
| 3892 | inline bool is_undetectable() { |
| 3893 | return ((1 << kIsUndetectable) & bit_field()) != 0; |
| 3894 | } |
| 3895 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3896 | // Tells whether the instance has a call-as-function handler. |
| 3897 | inline void set_has_instance_call_handler() { |
| 3898 | set_bit_field(bit_field() | (1 << kHasInstanceCallHandler)); |
| 3899 | } |
| 3900 | |
| 3901 | inline bool has_instance_call_handler() { |
| 3902 | return ((1 << kHasInstanceCallHandler) & bit_field()) != 0; |
| 3903 | } |
| 3904 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 3905 | inline void set_is_extensible(bool value); |
| 3906 | inline bool is_extensible(); |
| 3907 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 3908 | inline void set_elements_kind(JSObject::ElementsKind elements_kind) { |
| 3909 | ASSERT(elements_kind < JSObject::kElementsKindCount); |
| 3910 | ASSERT(JSObject::kElementsKindCount <= (1 << kElementsKindBitCount)); |
| 3911 | set_bit_field2((bit_field2() & ~kElementsKindMask) | |
| 3912 | (elements_kind << kElementsKindShift)); |
| 3913 | ASSERT(this->elements_kind() == elements_kind); |
| 3914 | } |
| 3915 | |
| 3916 | inline JSObject::ElementsKind elements_kind() { |
| 3917 | return static_cast<JSObject::ElementsKind>( |
| 3918 | (bit_field2() & kElementsKindMask) >> kElementsKindShift); |
| 3919 | } |
| 3920 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 3921 | // Tells whether the instance has fast elements. |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 3922 | // Equivalent to instance->GetElementsKind() == FAST_ELEMENTS. |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 3923 | inline bool has_fast_elements() { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 3924 | return elements_kind() == JSObject::FAST_ELEMENTS; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 3925 | } |
| 3926 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 3927 | inline bool has_fast_double_elements() { |
| 3928 | return elements_kind() == JSObject::FAST_DOUBLE_ELEMENTS; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3929 | } |
| 3930 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3931 | inline bool has_external_array_elements() { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 3932 | JSObject::ElementsKind kind(elements_kind()); |
| 3933 | return kind >= JSObject::FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND && |
| 3934 | kind <= JSObject::LAST_EXTERNAL_ARRAY_ELEMENTS_KIND; |
| 3935 | } |
| 3936 | |
| 3937 | inline bool has_dictionary_elements() { |
| 3938 | return elements_kind() == JSObject::DICTIONARY_ELEMENTS; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3939 | } |
| 3940 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3941 | // Tells whether the map is attached to SharedFunctionInfo |
| 3942 | // (for inobject slack tracking). |
| 3943 | inline void set_attached_to_shared_function_info(bool value); |
| 3944 | |
| 3945 | inline bool attached_to_shared_function_info(); |
| 3946 | |
| 3947 | // Tells whether the map is shared between objects that may have different |
| 3948 | // behavior. If true, the map should never be modified, instead a clone |
| 3949 | // should be created and modified. |
| 3950 | inline void set_is_shared(bool value); |
| 3951 | |
| 3952 | inline bool is_shared(); |
| 3953 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3954 | // Tells whether the instance needs security checks when accessing its |
| 3955 | // properties. |
| 3956 | inline void set_is_access_check_needed(bool access_check_needed); |
| 3957 | inline bool is_access_check_needed(); |
| 3958 | |
| 3959 | // [prototype]: implicit prototype object. |
| 3960 | DECL_ACCESSORS(prototype, Object) |
| 3961 | |
| 3962 | // [constructor]: points back to the function responsible for this map. |
| 3963 | DECL_ACCESSORS(constructor, Object) |
| 3964 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3965 | inline JSFunction* unchecked_constructor(); |
| 3966 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3967 | // Should only be called by the code that initializes map to set initial valid |
| 3968 | // value of the instance descriptor member. |
| 3969 | inline void init_instance_descriptors(); |
| 3970 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3971 | // [instance descriptors]: describes the object. |
| 3972 | DECL_ACCESSORS(instance_descriptors, DescriptorArray) |
| 3973 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3974 | // Sets the instance descriptor array for the map to be an empty descriptor |
| 3975 | // array. |
| 3976 | inline void clear_instance_descriptors(); |
| 3977 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3978 | // [stub cache]: contains stubs compiled for this map. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3979 | DECL_ACCESSORS(code_cache, Object) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3980 | |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 3981 | // [prototype transitions]: cache of prototype transitions. |
| 3982 | // Prototype transition is a transition that happens |
| 3983 | // when we change object's prototype to a new one. |
| 3984 | // Cache format: |
| 3985 | // 0: finger - index of the first free cell in the cache |
| 3986 | // 1 + 2 * i: prototype |
| 3987 | // 2 + 2 * i: target map |
| 3988 | DECL_ACCESSORS(prototype_transitions, FixedArray) |
| 3989 | inline FixedArray* unchecked_prototype_transitions(); |
| 3990 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 3991 | static const int kProtoTransitionHeaderSize = 1; |
| 3992 | static const int kProtoTransitionNumberOfEntriesOffset = 0; |
| 3993 | static const int kProtoTransitionElementsPerEntry = 2; |
| 3994 | static const int kProtoTransitionPrototypeOffset = 0; |
| 3995 | static const int kProtoTransitionMapOffset = 1; |
| 3996 | |
| 3997 | inline int NumberOfProtoTransitions() { |
| 3998 | FixedArray* cache = unchecked_prototype_transitions(); |
| 3999 | if (cache->length() == 0) return 0; |
| 4000 | return |
| 4001 | Smi::cast(cache->get(kProtoTransitionNumberOfEntriesOffset))->value(); |
| 4002 | } |
| 4003 | |
| 4004 | inline void SetNumberOfProtoTransitions(int value) { |
| 4005 | FixedArray* cache = unchecked_prototype_transitions(); |
| 4006 | ASSERT(cache->length() != 0); |
| 4007 | cache->set_unchecked(kProtoTransitionNumberOfEntriesOffset, |
| 4008 | Smi::FromInt(value)); |
| 4009 | } |
| 4010 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4011 | // Lookup in the map's instance descriptors and fill out the result |
| 4012 | // with the given holder if the name is found. The holder may be |
| 4013 | // NULL when this function is used from the compiler. |
| 4014 | void LookupInDescriptors(JSObject* holder, |
| 4015 | String* name, |
| 4016 | LookupResult* result); |
| 4017 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 4018 | MUST_USE_RESULT MaybeObject* CopyDropDescriptors(); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4019 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 4020 | MUST_USE_RESULT MaybeObject* CopyNormalized(PropertyNormalizationMode mode, |
| 4021 | NormalizedMapSharingMode sharing); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4022 | |
| 4023 | // Returns a copy of the map, with all transitions dropped from the |
| 4024 | // instance descriptors. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 4025 | MUST_USE_RESULT MaybeObject* CopyDropTransitions(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4026 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 4027 | // Returns this map if it already has elements that are fast, otherwise |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 4028 | // returns a copy of the map, with all transitions dropped from the |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 4029 | // descriptors and the ElementsKind set to FAST_ELEMENTS. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 4030 | MUST_USE_RESULT inline MaybeObject* GetFastElementsMap(); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 4031 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 4032 | // Returns this map if it already has fast elements that are doubles, |
| 4033 | // otherwise returns a copy of the map, with all transitions dropped from the |
| 4034 | // descriptors and the ElementsKind set to FAST_DOUBLE_ELEMENTS. |
| 4035 | MUST_USE_RESULT inline MaybeObject* GetFastDoubleElementsMap(); |
| 4036 | |
| 4037 | // Returns this map if already has dictionary elements, otherwise returns a |
| 4038 | // copy of the map, with all transitions dropped from the descriptors and the |
| 4039 | // ElementsKind set to DICTIONARY_ELEMENTS. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 4040 | MUST_USE_RESULT inline MaybeObject* GetSlowElementsMap(); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 4041 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4042 | // 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^] | 4043 | // ElementsKind set to one of the value corresponding to array_type. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4044 | MUST_USE_RESULT MaybeObject* GetExternalArrayElementsMap( |
| 4045 | ExternalArrayType array_type, |
| 4046 | bool safe_to_add_transition); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 4047 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4048 | // Returns the property index for name (only valid for FAST MODE). |
| 4049 | int PropertyIndexFor(String* name); |
| 4050 | |
| 4051 | // Returns the next free property index (only valid for FAST MODE). |
| 4052 | int NextFreePropertyIndex(); |
| 4053 | |
| 4054 | // Returns the number of properties described in instance_descriptors. |
| 4055 | int NumberOfDescribedProperties(); |
| 4056 | |
| 4057 | // Casting. |
| 4058 | static inline Map* cast(Object* obj); |
| 4059 | |
| 4060 | // Locate an accessor in the instance descriptor. |
| 4061 | AccessorDescriptor* FindAccessor(String* name); |
| 4062 | |
| 4063 | // Code cache operations. |
| 4064 | |
| 4065 | // Clears the code cache. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4066 | inline void ClearCodeCache(Heap* heap); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4067 | |
| 4068 | // Update code cache. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 4069 | MUST_USE_RESULT MaybeObject* UpdateCodeCache(String* name, Code* code); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4070 | |
| 4071 | // Returns the found code or undefined if absent. |
| 4072 | Object* FindInCodeCache(String* name, Code::Flags flags); |
| 4073 | |
| 4074 | // Returns the non-negative index of the code object if it is in the |
| 4075 | // cache and -1 otherwise. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4076 | int IndexInCodeCache(Object* name, Code* code); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4077 | |
| 4078 | // Removes a code object from the code cache at the given index. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4079 | void RemoveFromCodeCache(String* name, Code* code, int index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4080 | |
| 4081 | // For every transition in this map, makes the transition's |
| 4082 | // target's prototype pointer point back to this map. |
| 4083 | // This is undone in MarkCompactCollector::ClearNonLiveTransitions(). |
| 4084 | void CreateBackPointers(); |
| 4085 | |
| 4086 | // Set all map transitions from this map to dead maps to null. |
| 4087 | // Also, restore the original prototype on the targets of these |
| 4088 | // transitions, so that we do not process this map again while |
| 4089 | // following back pointers. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4090 | void ClearNonLiveTransitions(Heap* heap, Object* real_prototype); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4091 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 4092 | // Computes a hash value for this map, to be used in HashTables and such. |
| 4093 | int Hash(); |
| 4094 | |
| 4095 | // Compares this map to another to see if they describe equivalent objects. |
| 4096 | // If |mode| is set to CLEAR_INOBJECT_PROPERTIES, |other| is treated as if |
| 4097 | // it had exactly zero inobject properties. |
| 4098 | // The "shared" flags of both this map and |other| are ignored. |
| 4099 | bool EquivalentToForNormalization(Map* other, PropertyNormalizationMode mode); |
| 4100 | |
| 4101 | // Returns true if this map and |other| describe equivalent objects. |
| 4102 | // The "shared" flags of both this map and |other| are ignored. |
| 4103 | bool EquivalentTo(Map* other) { |
| 4104 | return EquivalentToForNormalization(other, KEEP_INOBJECT_PROPERTIES); |
| 4105 | } |
| 4106 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4107 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4108 | #ifdef OBJECT_PRINT |
| 4109 | inline void MapPrint() { |
| 4110 | MapPrint(stdout); |
| 4111 | } |
| 4112 | void MapPrint(FILE* out); |
| 4113 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4114 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4115 | void MapVerify(); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4116 | void SharedMapVerify(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4117 | #endif |
| 4118 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 4119 | inline int visitor_id(); |
| 4120 | inline void set_visitor_id(int visitor_id); |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 4121 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4122 | // Returns the isolate/heap this map belongs to. |
| 4123 | inline Isolate* isolate(); |
| 4124 | inline Heap* heap(); |
| 4125 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4126 | typedef void (*TraverseCallback)(Map* map, void* data); |
| 4127 | |
| 4128 | void TraverseTransitionTree(TraverseCallback callback, void* data); |
| 4129 | |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 4130 | static const int kMaxCachedPrototypeTransitions = 256; |
| 4131 | |
| 4132 | Object* GetPrototypeTransition(Object* prototype); |
| 4133 | |
| 4134 | MaybeObject* PutPrototypeTransition(Object* prototype, Map* map); |
| 4135 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4136 | static const int kMaxPreAllocatedPropertyFields = 255; |
| 4137 | |
| 4138 | // Layout description. |
| 4139 | static const int kInstanceSizesOffset = HeapObject::kHeaderSize; |
| 4140 | static const int kInstanceAttributesOffset = kInstanceSizesOffset + kIntSize; |
| 4141 | static const int kPrototypeOffset = kInstanceAttributesOffset + kIntSize; |
| 4142 | static const int kConstructorOffset = kPrototypeOffset + kPointerSize; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4143 | // Storage for instance descriptors is overloaded to also contain additional |
| 4144 | // map flags when unused (bit_field3). When the map has instance descriptors, |
| 4145 | // the flags are transferred to the instance descriptor array and accessed |
| 4146 | // through an extra indirection. |
| 4147 | // TODO(1399): It should be possible to make room for bit_field3 in the map |
| 4148 | // without overloading the instance descriptors field, but the map is |
| 4149 | // currently perfectly aligned to 32 bytes and extending it at all would |
| 4150 | // double its size. After the increment GC work lands, this size restriction |
| 4151 | // could be loosened and bit_field3 moved directly back in the map. |
| 4152 | static const int kInstanceDescriptorsOrBitField3Offset = |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4153 | kConstructorOffset + kPointerSize; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4154 | static const int kCodeCacheOffset = |
| 4155 | kInstanceDescriptorsOrBitField3Offset + kPointerSize; |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 4156 | static const int kPrototypeTransitionsOffset = |
| 4157 | kCodeCacheOffset + kPointerSize; |
| 4158 | static const int kPadStart = kPrototypeTransitionsOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4159 | static const int kSize = MAP_POINTER_ALIGN(kPadStart); |
| 4160 | |
| 4161 | // Layout of pointer fields. Heap iteration code relies on them |
| 4162 | // being continiously allocated. |
| 4163 | static const int kPointerFieldsBeginOffset = Map::kPrototypeOffset; |
| 4164 | static const int kPointerFieldsEndOffset = |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 4165 | Map::kPrototypeTransitionsOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4166 | |
| 4167 | // Byte offsets within kInstanceSizesOffset. |
| 4168 | static const int kInstanceSizeOffset = kInstanceSizesOffset + 0; |
| 4169 | static const int kInObjectPropertiesByte = 1; |
| 4170 | static const int kInObjectPropertiesOffset = |
| 4171 | kInstanceSizesOffset + kInObjectPropertiesByte; |
| 4172 | static const int kPreAllocatedPropertyFieldsByte = 2; |
| 4173 | static const int kPreAllocatedPropertyFieldsOffset = |
| 4174 | kInstanceSizesOffset + kPreAllocatedPropertyFieldsByte; |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 4175 | static const int kVisitorIdByte = 3; |
| 4176 | static const int kVisitorIdOffset = kInstanceSizesOffset + kVisitorIdByte; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4177 | |
| 4178 | // Byte offsets within kInstanceAttributesOffset attributes. |
| 4179 | static const int kInstanceTypeOffset = kInstanceAttributesOffset + 0; |
| 4180 | static const int kUnusedPropertyFieldsOffset = kInstanceAttributesOffset + 1; |
| 4181 | static const int kBitFieldOffset = kInstanceAttributesOffset + 2; |
| 4182 | static const int kBitField2Offset = kInstanceAttributesOffset + 3; |
| 4183 | |
| 4184 | STATIC_CHECK(kInstanceTypeOffset == Internals::kMapInstanceTypeOffset); |
| 4185 | |
| 4186 | // Bit positions for bit field. |
| 4187 | static const int kUnused = 0; // To be used for marking recently used maps. |
| 4188 | static const int kHasNonInstancePrototype = 1; |
| 4189 | static const int kIsHiddenPrototype = 2; |
| 4190 | static const int kHasNamedInterceptor = 3; |
| 4191 | static const int kHasIndexedInterceptor = 4; |
| 4192 | static const int kIsUndetectable = 5; |
| 4193 | static const int kHasInstanceCallHandler = 6; |
| 4194 | static const int kIsAccessCheckNeeded = 7; |
| 4195 | |
| 4196 | // Bit positions for bit field 2 |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 4197 | static const int kIsExtensible = 0; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4198 | static const int kFunctionWithPrototype = 1; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 4199 | static const int kStringWrapperSafeForDefaultValueOf = 2; |
| 4200 | static const int kAttachedToSharedFunctionInfo = 3; |
| 4201 | // No bits can be used after kElementsKindFirstBit, they are all reserved for |
| 4202 | // storing ElementKind. for anything other than storing the ElementKind. |
| 4203 | static const int kElementsKindShift = 4; |
| 4204 | static const int kElementsKindBitCount = 4; |
| 4205 | |
| 4206 | // Derived values from bit field 2 |
| 4207 | static const int kElementsKindMask = (-1 << kElementsKindShift) & |
| 4208 | ((1 << (kElementsKindShift + kElementsKindBitCount)) - 1); |
| 4209 | static const int8_t kMaximumBitField2FastElementValue = static_cast<int8_t>( |
| 4210 | (JSObject::FAST_ELEMENTS + 1) << Map::kElementsKindShift) - 1; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4211 | |
| 4212 | // Bit positions for bit field 3 |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 4213 | static const int kIsShared = 0; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4214 | |
| 4215 | // Layout of the default cache. It holds alternating name and code objects. |
| 4216 | static const int kCodeCacheEntrySize = 2; |
| 4217 | static const int kCodeCacheEntryNameOffset = 0; |
| 4218 | static const int kCodeCacheEntryCodeOffset = 1; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4219 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 4220 | typedef FixedBodyDescriptor<kPointerFieldsBeginOffset, |
| 4221 | kPointerFieldsEndOffset, |
| 4222 | kSize> BodyDescriptor; |
| 4223 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4224 | private: |
| 4225 | DISALLOW_IMPLICIT_CONSTRUCTORS(Map); |
| 4226 | }; |
| 4227 | |
| 4228 | |
| 4229 | // An abstract superclass, a marker class really, for simple structure classes. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4230 | // It doesn't carry much functionality but allows struct classes to be |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4231 | // identified in the type system. |
| 4232 | class Struct: public HeapObject { |
| 4233 | public: |
| 4234 | inline void InitializeBody(int object_size); |
| 4235 | static inline Struct* cast(Object* that); |
| 4236 | }; |
| 4237 | |
| 4238 | |
| 4239 | // Script describes a script which has been added to the VM. |
| 4240 | class Script: public Struct { |
| 4241 | public: |
| 4242 | // Script types. |
| 4243 | enum Type { |
| 4244 | TYPE_NATIVE = 0, |
| 4245 | TYPE_EXTENSION = 1, |
| 4246 | TYPE_NORMAL = 2 |
| 4247 | }; |
| 4248 | |
| 4249 | // Script compilation types. |
| 4250 | enum CompilationType { |
| 4251 | COMPILATION_TYPE_HOST = 0, |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 4252 | COMPILATION_TYPE_EVAL = 1 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4253 | }; |
| 4254 | |
| 4255 | // [source]: the script source. |
| 4256 | DECL_ACCESSORS(source, Object) |
| 4257 | |
| 4258 | // [name]: the script name. |
| 4259 | DECL_ACCESSORS(name, Object) |
| 4260 | |
| 4261 | // [id]: the script id. |
| 4262 | DECL_ACCESSORS(id, Object) |
| 4263 | |
| 4264 | // [line_offset]: script line offset in resource from where it was extracted. |
| 4265 | DECL_ACCESSORS(line_offset, Smi) |
| 4266 | |
| 4267 | // [column_offset]: script column offset in resource from where it was |
| 4268 | // extracted. |
| 4269 | DECL_ACCESSORS(column_offset, Smi) |
| 4270 | |
| 4271 | // [data]: additional data associated with this script. |
| 4272 | DECL_ACCESSORS(data, Object) |
| 4273 | |
| 4274 | // [context_data]: context data for the context this script was compiled in. |
| 4275 | DECL_ACCESSORS(context_data, Object) |
| 4276 | |
| 4277 | // [wrapper]: the wrapper cache. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4278 | DECL_ACCESSORS(wrapper, Foreign) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4279 | |
| 4280 | // [type]: the script type. |
| 4281 | DECL_ACCESSORS(type, Smi) |
| 4282 | |
| 4283 | // [compilation]: how the the script was compiled. |
| 4284 | DECL_ACCESSORS(compilation_type, Smi) |
| 4285 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4286 | // [line_ends]: FixedArray of line ends positions. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4287 | DECL_ACCESSORS(line_ends, Object) |
| 4288 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4289 | // [eval_from_shared]: for eval scripts the shared funcion info for the |
| 4290 | // function from which eval was called. |
| 4291 | DECL_ACCESSORS(eval_from_shared, Object) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4292 | |
| 4293 | // [eval_from_instructions_offset]: the instruction offset in the code for the |
| 4294 | // function from which eval was called where eval was called. |
| 4295 | DECL_ACCESSORS(eval_from_instructions_offset, Smi) |
| 4296 | |
| 4297 | static inline Script* cast(Object* obj); |
| 4298 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 4299 | // If script source is an external string, check that the underlying |
| 4300 | // resource is accessible. Otherwise, always return true. |
| 4301 | inline bool HasValidSource(); |
| 4302 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4303 | #ifdef OBJECT_PRINT |
| 4304 | inline void ScriptPrint() { |
| 4305 | ScriptPrint(stdout); |
| 4306 | } |
| 4307 | void ScriptPrint(FILE* out); |
| 4308 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4309 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4310 | void ScriptVerify(); |
| 4311 | #endif |
| 4312 | |
| 4313 | static const int kSourceOffset = HeapObject::kHeaderSize; |
| 4314 | static const int kNameOffset = kSourceOffset + kPointerSize; |
| 4315 | static const int kLineOffsetOffset = kNameOffset + kPointerSize; |
| 4316 | static const int kColumnOffsetOffset = kLineOffsetOffset + kPointerSize; |
| 4317 | static const int kDataOffset = kColumnOffsetOffset + kPointerSize; |
| 4318 | static const int kContextOffset = kDataOffset + kPointerSize; |
| 4319 | static const int kWrapperOffset = kContextOffset + kPointerSize; |
| 4320 | static const int kTypeOffset = kWrapperOffset + kPointerSize; |
| 4321 | static const int kCompilationTypeOffset = kTypeOffset + kPointerSize; |
| 4322 | static const int kLineEndsOffset = kCompilationTypeOffset + kPointerSize; |
| 4323 | static const int kIdOffset = kLineEndsOffset + kPointerSize; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4324 | static const int kEvalFromSharedOffset = kIdOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4325 | static const int kEvalFrominstructionsOffsetOffset = |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4326 | kEvalFromSharedOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4327 | static const int kSize = kEvalFrominstructionsOffsetOffset + kPointerSize; |
| 4328 | |
| 4329 | private: |
| 4330 | DISALLOW_IMPLICIT_CONSTRUCTORS(Script); |
| 4331 | }; |
| 4332 | |
| 4333 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4334 | // List of builtin functions we want to identify to improve code |
| 4335 | // generation. |
| 4336 | // |
| 4337 | // Each entry has a name of a global object property holding an object |
| 4338 | // optionally followed by ".prototype", a name of a builtin function |
| 4339 | // on the object (the one the id is set for), and a label. |
| 4340 | // |
| 4341 | // Installation of ids for the selected builtin functions is handled |
| 4342 | // by the bootstrapper. |
| 4343 | // |
| 4344 | // NOTE: Order is important: math functions should be at the end of |
| 4345 | // the list and MathFloor should be the first math function. |
| 4346 | #define FUNCTIONS_WITH_ID_LIST(V) \ |
| 4347 | V(Array.prototype, push, ArrayPush) \ |
| 4348 | V(Array.prototype, pop, ArrayPop) \ |
Ben Murdoch | 42effa5 | 2011-08-19 16:40:31 +0100 | [diff] [blame] | 4349 | V(Function.prototype, apply, FunctionApply) \ |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4350 | V(String.prototype, charCodeAt, StringCharCodeAt) \ |
| 4351 | V(String.prototype, charAt, StringCharAt) \ |
| 4352 | V(String, fromCharCode, StringFromCharCode) \ |
| 4353 | V(Math, floor, MathFloor) \ |
| 4354 | V(Math, round, MathRound) \ |
| 4355 | V(Math, ceil, MathCeil) \ |
| 4356 | V(Math, abs, MathAbs) \ |
| 4357 | V(Math, log, MathLog) \ |
| 4358 | V(Math, sin, MathSin) \ |
| 4359 | V(Math, cos, MathCos) \ |
| 4360 | V(Math, tan, MathTan) \ |
| 4361 | V(Math, asin, MathASin) \ |
| 4362 | V(Math, acos, MathACos) \ |
| 4363 | V(Math, atan, MathATan) \ |
| 4364 | V(Math, exp, MathExp) \ |
| 4365 | V(Math, sqrt, MathSqrt) \ |
| 4366 | V(Math, pow, MathPow) |
| 4367 | |
| 4368 | |
| 4369 | enum BuiltinFunctionId { |
| 4370 | #define DECLARE_FUNCTION_ID(ignored1, ignore2, name) \ |
| 4371 | k##name, |
| 4372 | FUNCTIONS_WITH_ID_LIST(DECLARE_FUNCTION_ID) |
| 4373 | #undef DECLARE_FUNCTION_ID |
| 4374 | // Fake id for a special case of Math.pow. Note, it continues the |
| 4375 | // list of math functions. |
| 4376 | kMathPowHalf, |
| 4377 | kFirstMathFunctionId = kMathFloor |
| 4378 | }; |
| 4379 | |
| 4380 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4381 | // SharedFunctionInfo describes the JSFunction information that can be |
| 4382 | // shared by multiple instances of the function. |
| 4383 | class SharedFunctionInfo: public HeapObject { |
| 4384 | public: |
| 4385 | // [name]: Function name. |
| 4386 | DECL_ACCESSORS(name, Object) |
| 4387 | |
| 4388 | // [code]: Function code. |
| 4389 | DECL_ACCESSORS(code, Code) |
| 4390 | |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 4391 | // [scope_info]: Scope info. |
| 4392 | DECL_ACCESSORS(scope_info, SerializedScopeInfo) |
| 4393 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4394 | // [construct stub]: Code stub for constructing instances of this function. |
| 4395 | DECL_ACCESSORS(construct_stub, Code) |
| 4396 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 4397 | inline Code* unchecked_code(); |
| 4398 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4399 | // Returns if this function has been compiled to native code yet. |
| 4400 | inline bool is_compiled(); |
| 4401 | |
| 4402 | // [length]: The function length - usually the number of declared parameters. |
| 4403 | // Use up to 2^30 parameters. |
| 4404 | inline int length(); |
| 4405 | inline void set_length(int value); |
| 4406 | |
| 4407 | // [formal parameter count]: The declared number of parameters. |
| 4408 | inline int formal_parameter_count(); |
| 4409 | inline void set_formal_parameter_count(int value); |
| 4410 | |
| 4411 | // Set the formal parameter count so the function code will be |
| 4412 | // called without using argument adaptor frames. |
| 4413 | inline void DontAdaptArguments(); |
| 4414 | |
| 4415 | // [expected_nof_properties]: Expected number of properties for the function. |
| 4416 | inline int expected_nof_properties(); |
| 4417 | inline void set_expected_nof_properties(int value); |
| 4418 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4419 | // Inobject slack tracking is the way to reclaim unused inobject space. |
| 4420 | // |
| 4421 | // The instance size is initially determined by adding some slack to |
| 4422 | // expected_nof_properties (to allow for a few extra properties added |
| 4423 | // after the constructor). There is no guarantee that the extra space |
| 4424 | // will not be wasted. |
| 4425 | // |
| 4426 | // Here is the algorithm to reclaim the unused inobject space: |
| 4427 | // - Detect the first constructor call for this SharedFunctionInfo. |
| 4428 | // When it happens enter the "in progress" state: remember the |
| 4429 | // constructor's initial_map and install a special construct stub that |
| 4430 | // counts constructor calls. |
| 4431 | // - While the tracking is in progress create objects filled with |
| 4432 | // one_pointer_filler_map instead of undefined_value. This way they can be |
| 4433 | // resized quickly and safely. |
| 4434 | // - Once enough (kGenerousAllocationCount) objects have been created |
| 4435 | // compute the 'slack' (traverse the map transition tree starting from the |
| 4436 | // initial_map and find the lowest value of unused_property_fields). |
| 4437 | // - Traverse the transition tree again and decrease the instance size |
| 4438 | // of every map. Existing objects will resize automatically (they are |
| 4439 | // filled with one_pointer_filler_map). All further allocations will |
| 4440 | // use the adjusted instance size. |
| 4441 | // - Decrease expected_nof_properties so that an allocations made from |
| 4442 | // another context will use the adjusted instance size too. |
| 4443 | // - Exit "in progress" state by clearing the reference to the initial_map |
| 4444 | // and setting the regular construct stub (generic or inline). |
| 4445 | // |
| 4446 | // The above is the main event sequence. Some special cases are possible |
| 4447 | // while the tracking is in progress: |
| 4448 | // |
| 4449 | // - GC occurs. |
| 4450 | // Check if the initial_map is referenced by any live objects (except this |
| 4451 | // SharedFunctionInfo). If it is, continue tracking as usual. |
| 4452 | // If it is not, clear the reference and reset the tracking state. The |
| 4453 | // tracking will be initiated again on the next constructor call. |
| 4454 | // |
| 4455 | // - The constructor is called from another context. |
| 4456 | // Immediately complete the tracking, perform all the necessary changes |
| 4457 | // to maps. This is necessary because there is no efficient way to track |
| 4458 | // multiple initial_maps. |
| 4459 | // Proceed to create an object in the current context (with the adjusted |
| 4460 | // size). |
| 4461 | // |
| 4462 | // - A different constructor function sharing the same SharedFunctionInfo is |
| 4463 | // called in the same context. This could be another closure in the same |
| 4464 | // context, or the first function could have been disposed. |
| 4465 | // This is handled the same way as the previous case. |
| 4466 | // |
| 4467 | // Important: inobject slack tracking is not attempted during the snapshot |
| 4468 | // creation. |
| 4469 | |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 4470 | static const int kGenerousAllocationCount = 8; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4471 | |
| 4472 | // [construction_count]: Counter for constructor calls made during |
| 4473 | // the tracking phase. |
| 4474 | inline int construction_count(); |
| 4475 | inline void set_construction_count(int value); |
| 4476 | |
| 4477 | // [initial_map]: initial map of the first function called as a constructor. |
| 4478 | // Saved for the duration of the tracking phase. |
| 4479 | // This is a weak link (GC resets it to undefined_value if no other live |
| 4480 | // object reference this map). |
| 4481 | DECL_ACCESSORS(initial_map, Object) |
| 4482 | |
| 4483 | // True if the initial_map is not undefined and the countdown stub is |
| 4484 | // installed. |
| 4485 | inline bool IsInobjectSlackTrackingInProgress(); |
| 4486 | |
| 4487 | // Starts the tracking. |
| 4488 | // Stores the initial map and installs the countdown stub. |
| 4489 | // IsInobjectSlackTrackingInProgress is normally true after this call, |
| 4490 | // except when tracking have not been started (e.g. the map has no unused |
| 4491 | // properties or the snapshot is being built). |
| 4492 | void StartInobjectSlackTracking(Map* map); |
| 4493 | |
| 4494 | // Completes the tracking. |
| 4495 | // IsInobjectSlackTrackingInProgress is false after this call. |
| 4496 | void CompleteInobjectSlackTracking(); |
| 4497 | |
| 4498 | // Clears the initial_map before the GC marking phase to ensure the reference |
| 4499 | // is weak. IsInobjectSlackTrackingInProgress is false after this call. |
| 4500 | void DetachInitialMap(); |
| 4501 | |
| 4502 | // Restores the link to the initial map after the GC marking phase. |
| 4503 | // IsInobjectSlackTrackingInProgress is true after this call. |
| 4504 | void AttachInitialMap(Map* map); |
| 4505 | |
| 4506 | // False if there are definitely no live objects created from this function. |
| 4507 | // True if live objects _may_ exist (existence not guaranteed). |
| 4508 | // May go back from true to false after GC. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 4509 | DECL_BOOLEAN_ACCESSORS(live_objects_may_exist) |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4510 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4511 | // [instance class name]: class name for instances. |
| 4512 | DECL_ACCESSORS(instance_class_name, Object) |
| 4513 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4514 | // [function data]: This field holds some additional data for function. |
| 4515 | // Currently it either has FunctionTemplateInfo to make benefit the API |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4516 | // or Smi identifying a builtin function. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4517 | // In the long run we don't want all functions to have this field but |
| 4518 | // we can fix that when we have a better model for storing hidden data |
| 4519 | // on objects. |
| 4520 | DECL_ACCESSORS(function_data, Object) |
| 4521 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4522 | inline bool IsApiFunction(); |
| 4523 | inline FunctionTemplateInfo* get_api_func_data(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4524 | inline bool HasBuiltinFunctionId(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4525 | inline BuiltinFunctionId builtin_function_id(); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4526 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4527 | // [script info]: Script from which the function originates. |
| 4528 | DECL_ACCESSORS(script, Object) |
| 4529 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4530 | // [num_literals]: Number of literals used by this function. |
| 4531 | inline int num_literals(); |
| 4532 | inline void set_num_literals(int value); |
| 4533 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4534 | // [start_position_and_type]: Field used to store both the source code |
| 4535 | // position, whether or not the function is a function expression, |
| 4536 | // and whether or not the function is a toplevel function. The two |
| 4537 | // least significants bit indicates whether the function is an |
| 4538 | // expression and the rest contains the source code position. |
| 4539 | inline int start_position_and_type(); |
| 4540 | inline void set_start_position_and_type(int value); |
| 4541 | |
| 4542 | // [debug info]: Debug information. |
| 4543 | DECL_ACCESSORS(debug_info, Object) |
| 4544 | |
| 4545 | // [inferred name]: Name inferred from variable or property |
| 4546 | // assignment of this function. Used to facilitate debugging and |
| 4547 | // profiling of JavaScript code written in OO style, where almost |
| 4548 | // all functions are anonymous but are assigned to object |
| 4549 | // properties. |
| 4550 | DECL_ACCESSORS(inferred_name, String) |
| 4551 | |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 4552 | // The function's name if it is non-empty, otherwise the inferred name. |
| 4553 | String* DebugName(); |
| 4554 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4555 | // Position of the 'function' token in the script source. |
| 4556 | inline int function_token_position(); |
| 4557 | inline void set_function_token_position(int function_token_position); |
| 4558 | |
| 4559 | // Position of this function in the script source. |
| 4560 | inline int start_position(); |
| 4561 | inline void set_start_position(int start_position); |
| 4562 | |
| 4563 | // End position of this function in the script source. |
| 4564 | inline int end_position(); |
| 4565 | inline void set_end_position(int end_position); |
| 4566 | |
| 4567 | // Is this function a function expression in the source code. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 4568 | DECL_BOOLEAN_ACCESSORS(is_expression) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4569 | |
| 4570 | // Is this function a top-level function (scripts, evals). |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 4571 | DECL_BOOLEAN_ACCESSORS(is_toplevel) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4572 | |
| 4573 | // Bit field containing various information collected by the compiler to |
| 4574 | // drive optimization. |
| 4575 | inline int compiler_hints(); |
| 4576 | inline void set_compiler_hints(int value); |
| 4577 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4578 | // A counter used to determine when to stress the deoptimizer with a |
| 4579 | // deopt. |
| 4580 | inline Smi* deopt_counter(); |
| 4581 | inline void set_deopt_counter(Smi* counter); |
| 4582 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4583 | // Add information on assignments of the form this.x = ...; |
| 4584 | void SetThisPropertyAssignmentsInfo( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4585 | bool has_only_simple_this_property_assignments, |
| 4586 | FixedArray* this_property_assignments); |
| 4587 | |
| 4588 | // Clear information on assignments of the form this.x = ...; |
| 4589 | void ClearThisPropertyAssignmentsInfo(); |
| 4590 | |
| 4591 | // Indicate that this function only consists of assignments of the form |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4592 | // this.x = y; where y is either a constant or refers to an argument. |
| 4593 | inline bool has_only_simple_this_property_assignments(); |
| 4594 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4595 | // Indicates if this function can be lazy compiled. |
| 4596 | // This is used to determine if we can safely flush code from a function |
| 4597 | // 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^] | 4598 | DECL_BOOLEAN_ACCESSORS(allows_lazy_compilation) |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4599 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 4600 | // Indicates how many full GCs this function has survived with assigned |
| 4601 | // code object. Used to determine when it is relatively safe to flush |
| 4602 | // this code object and replace it with lazy compilation stub. |
| 4603 | // Age is reset when GC notices that the code object is referenced |
| 4604 | // from the stack or compilation cache. |
| 4605 | inline int code_age(); |
| 4606 | inline void set_code_age(int age); |
| 4607 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4608 | // Indicates whether optimizations have been disabled for this |
| 4609 | // shared function info. If a function is repeatedly optimized or if |
| 4610 | // we cannot optimize the function we disable optimization to avoid |
| 4611 | // spending time attempting to optimize it again. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 4612 | DECL_BOOLEAN_ACCESSORS(optimization_disabled) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4613 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 4614 | // Indicates whether the function is a strict mode function. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 4615 | DECL_BOOLEAN_ACCESSORS(strict_mode) |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 4616 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 4617 | // False if the function definitely does not allocate an arguments object. |
| 4618 | DECL_BOOLEAN_ACCESSORS(uses_arguments) |
| 4619 | |
| 4620 | // True if the function has any duplicated parameter names. |
| 4621 | DECL_BOOLEAN_ACCESSORS(has_duplicate_parameters) |
| 4622 | |
| 4623 | // Indicates whether the function is a native function. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4624 | // These needs special threatment in .call and .apply since |
| 4625 | // null passed as the receiver should not be translated to the |
| 4626 | // global object. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 4627 | DECL_BOOLEAN_ACCESSORS(native) |
| 4628 | |
| 4629 | // Indicates that the function was created by the Function function. |
| 4630 | // Though it's anonymous, toString should treat it as if it had the name |
| 4631 | // "anonymous". We don't set the name itself so that the system does not |
| 4632 | // see a binding for it. |
| 4633 | DECL_BOOLEAN_ACCESSORS(name_should_print_as_anonymous) |
| 4634 | |
| 4635 | // Indicates whether the function is a bound function created using |
| 4636 | // the bind function. |
| 4637 | DECL_BOOLEAN_ACCESSORS(bound) |
| 4638 | |
| 4639 | // Indicates that the function is anonymous (the name field can be set |
| 4640 | // through the API, which does not change this flag). |
| 4641 | DECL_BOOLEAN_ACCESSORS(is_anonymous) |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4642 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4643 | // Indicates whether or not the code in the shared function support |
| 4644 | // deoptimization. |
| 4645 | inline bool has_deoptimization_support(); |
| 4646 | |
| 4647 | // Enable deoptimization support through recompiled code. |
| 4648 | void EnableDeoptimizationSupport(Code* recompiled); |
| 4649 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4650 | // Disable (further) attempted optimization of all functions sharing this |
| 4651 | // shared function info. The function is the one we actually tried to |
| 4652 | // optimize. |
| 4653 | void DisableOptimization(JSFunction* function); |
| 4654 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4655 | // Lookup the bailout ID and ASSERT that it exists in the non-optimized |
| 4656 | // code, returns whether it asserted (i.e., always true if assertions are |
| 4657 | // disabled). |
| 4658 | bool VerifyBailoutId(int id); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 4659 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 4660 | // Check whether a inlined constructor can be generated with the given |
| 4661 | // prototype. |
| 4662 | bool CanGenerateInlineConstructor(Object* prototype); |
| 4663 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4664 | // Prevents further attempts to generate inline constructors. |
| 4665 | // To be called if generation failed for any reason. |
| 4666 | void ForbidInlineConstructor(); |
| 4667 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4668 | // For functions which only contains this property assignments this provides |
| 4669 | // access to the names for the properties assigned. |
| 4670 | DECL_ACCESSORS(this_property_assignments, Object) |
| 4671 | inline int this_property_assignments_count(); |
| 4672 | inline void set_this_property_assignments_count(int value); |
| 4673 | String* GetThisPropertyAssignmentName(int index); |
| 4674 | bool IsThisPropertyAssignmentArgument(int index); |
| 4675 | int GetThisPropertyAssignmentArgument(int index); |
| 4676 | Object* GetThisPropertyAssignmentConstant(int index); |
| 4677 | |
| 4678 | // [source code]: Source code for the function. |
| 4679 | bool HasSourceCode(); |
| 4680 | Object* GetSourceCode(); |
| 4681 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4682 | inline int opt_count(); |
| 4683 | inline void set_opt_count(int opt_count); |
| 4684 | |
| 4685 | // Source size of this function. |
| 4686 | int SourceSize(); |
| 4687 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4688 | // Calculate the instance size. |
| 4689 | int CalculateInstanceSize(); |
| 4690 | |
| 4691 | // Calculate the number of in-object properties. |
| 4692 | int CalculateInObjectProperties(); |
| 4693 | |
| 4694 | // Dispatched behavior. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4695 | // Set max_length to -1 for unlimited length. |
| 4696 | void SourceCodePrint(StringStream* accumulator, int max_length); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4697 | #ifdef OBJECT_PRINT |
| 4698 | inline void SharedFunctionInfoPrint() { |
| 4699 | SharedFunctionInfoPrint(stdout); |
| 4700 | } |
| 4701 | void SharedFunctionInfoPrint(FILE* out); |
| 4702 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4703 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4704 | void SharedFunctionInfoVerify(); |
| 4705 | #endif |
| 4706 | |
| 4707 | // Casting. |
| 4708 | static inline SharedFunctionInfo* cast(Object* obj); |
| 4709 | |
| 4710 | // Constants. |
| 4711 | static const int kDontAdaptArgumentsSentinel = -1; |
| 4712 | |
| 4713 | // Layout description. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4714 | // Pointer fields. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4715 | static const int kNameOffset = HeapObject::kHeaderSize; |
| 4716 | static const int kCodeOffset = kNameOffset + kPointerSize; |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 4717 | static const int kScopeInfoOffset = kCodeOffset + kPointerSize; |
| 4718 | static const int kConstructStubOffset = kScopeInfoOffset + kPointerSize; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4719 | static const int kInstanceClassNameOffset = |
| 4720 | kConstructStubOffset + kPointerSize; |
| 4721 | static const int kFunctionDataOffset = |
| 4722 | kInstanceClassNameOffset + kPointerSize; |
| 4723 | static const int kScriptOffset = kFunctionDataOffset + kPointerSize; |
| 4724 | static const int kDebugInfoOffset = kScriptOffset + kPointerSize; |
| 4725 | static const int kInferredNameOffset = kDebugInfoOffset + kPointerSize; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4726 | static const int kInitialMapOffset = |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4727 | kInferredNameOffset + kPointerSize; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4728 | static const int kThisPropertyAssignmentsOffset = |
| 4729 | kInitialMapOffset + kPointerSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4730 | static const int kDeoptCounterOffset = |
| 4731 | kThisPropertyAssignmentsOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4732 | #if V8_HOST_ARCH_32_BIT |
| 4733 | // Smi fields. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4734 | static const int kLengthOffset = |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4735 | kDeoptCounterOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4736 | static const int kFormalParameterCountOffset = kLengthOffset + kPointerSize; |
| 4737 | static const int kExpectedNofPropertiesOffset = |
| 4738 | kFormalParameterCountOffset + kPointerSize; |
| 4739 | static const int kNumLiteralsOffset = |
| 4740 | kExpectedNofPropertiesOffset + kPointerSize; |
| 4741 | static const int kStartPositionAndTypeOffset = |
| 4742 | kNumLiteralsOffset + kPointerSize; |
| 4743 | static const int kEndPositionOffset = |
| 4744 | kStartPositionAndTypeOffset + kPointerSize; |
| 4745 | static const int kFunctionTokenPositionOffset = |
| 4746 | kEndPositionOffset + kPointerSize; |
| 4747 | static const int kCompilerHintsOffset = |
| 4748 | kFunctionTokenPositionOffset + kPointerSize; |
| 4749 | static const int kThisPropertyAssignmentsCountOffset = |
| 4750 | kCompilerHintsOffset + kPointerSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4751 | static const int kOptCountOffset = |
| 4752 | kThisPropertyAssignmentsCountOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4753 | // Total size. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4754 | static const int kSize = kOptCountOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4755 | #else |
| 4756 | // The only reason to use smi fields instead of int fields |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4757 | // is to allow iteration without maps decoding during |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4758 | // garbage collections. |
| 4759 | // To avoid wasting space on 64-bit architectures we use |
| 4760 | // the following trick: we group integer fields into pairs |
| 4761 | // First integer in each pair is shifted left by 1. |
| 4762 | // By doing this we guarantee that LSB of each kPointerSize aligned |
| 4763 | // word is not set and thus this word cannot be treated as pointer |
| 4764 | // to HeapObject during old space traversal. |
| 4765 | static const int kLengthOffset = |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4766 | kDeoptCounterOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4767 | static const int kFormalParameterCountOffset = |
| 4768 | kLengthOffset + kIntSize; |
| 4769 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4770 | static const int kExpectedNofPropertiesOffset = |
| 4771 | kFormalParameterCountOffset + kIntSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4772 | static const int kNumLiteralsOffset = |
| 4773 | kExpectedNofPropertiesOffset + kIntSize; |
| 4774 | |
| 4775 | static const int kEndPositionOffset = |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4776 | kNumLiteralsOffset + kIntSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4777 | static const int kStartPositionAndTypeOffset = |
| 4778 | kEndPositionOffset + kIntSize; |
| 4779 | |
| 4780 | static const int kFunctionTokenPositionOffset = |
| 4781 | kStartPositionAndTypeOffset + kIntSize; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4782 | static const int kCompilerHintsOffset = |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4783 | kFunctionTokenPositionOffset + kIntSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4784 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4785 | static const int kThisPropertyAssignmentsCountOffset = |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4786 | kCompilerHintsOffset + kIntSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4787 | static const int kOptCountOffset = |
| 4788 | kThisPropertyAssignmentsCountOffset + kIntSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4789 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4790 | // Total size. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4791 | static const int kSize = kOptCountOffset + kIntSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4792 | |
| 4793 | #endif |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4794 | |
| 4795 | // The construction counter for inobject slack tracking is stored in the |
| 4796 | // most significant byte of compiler_hints which is otherwise unused. |
| 4797 | // Its offset depends on the endian-ness of the architecture. |
| 4798 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
| 4799 | static const int kConstructionCountOffset = kCompilerHintsOffset + 3; |
| 4800 | #elif __BYTE_ORDER == __BIG_ENDIAN |
| 4801 | static const int kConstructionCountOffset = kCompilerHintsOffset + 0; |
| 4802 | #else |
| 4803 | #error Unknown byte ordering |
| 4804 | #endif |
| 4805 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4806 | static const int kAlignedSize = POINTER_SIZE_ALIGN(kSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4807 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 4808 | typedef FixedBodyDescriptor<kNameOffset, |
| 4809 | kThisPropertyAssignmentsOffset + kPointerSize, |
| 4810 | kSize> BodyDescriptor; |
| 4811 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4812 | // Bit positions in start_position_and_type. |
| 4813 | // The source code start position is in the 30 most significant bits of |
| 4814 | // the start_position_and_type field. |
| 4815 | static const int kIsExpressionBit = 0; |
| 4816 | static const int kIsTopLevelBit = 1; |
| 4817 | static const int kStartPositionShift = 2; |
| 4818 | static const int kStartPositionMask = ~((1 << kStartPositionShift) - 1); |
| 4819 | |
| 4820 | // Bit positions in compiler_hints. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 4821 | static const int kCodeAgeSize = 3; |
| 4822 | static const int kCodeAgeMask = (1 << kCodeAgeSize) - 1; |
| 4823 | |
| 4824 | enum CompilerHints { |
| 4825 | kHasOnlySimpleThisPropertyAssignments, |
| 4826 | kAllowLazyCompilation, |
| 4827 | kLiveObjectsMayExist, |
| 4828 | kCodeAgeShift, |
| 4829 | kOptimizationDisabled = kCodeAgeShift + kCodeAgeSize, |
| 4830 | kStrictModeFunction, |
| 4831 | kUsesArguments, |
| 4832 | kHasDuplicateParameters, |
| 4833 | kNative, |
| 4834 | kBoundFunction, |
| 4835 | kIsAnonymous, |
| 4836 | kNameShouldPrintAsAnonymous, |
| 4837 | kCompilerHintsCount // Pseudo entry |
| 4838 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4839 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4840 | private: |
| 4841 | #if V8_HOST_ARCH_32_BIT |
| 4842 | // On 32 bit platforms, compiler hints is a smi. |
| 4843 | static const int kCompilerHintsSmiTagSize = kSmiTagSize; |
| 4844 | static const int kCompilerHintsSize = kPointerSize; |
| 4845 | #else |
| 4846 | // On 64 bit platforms, compiler hints is not a smi, see comment above. |
| 4847 | static const int kCompilerHintsSmiTagSize = 0; |
| 4848 | static const int kCompilerHintsSize = kIntSize; |
| 4849 | #endif |
| 4850 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 4851 | STATIC_ASSERT(SharedFunctionInfo::kCompilerHintsCount <= |
| 4852 | SharedFunctionInfo::kCompilerHintsSize * kBitsPerByte); |
| 4853 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4854 | public: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4855 | // Constants for optimizing codegen for strict mode function and |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 4856 | // native tests. |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4857 | // Allows to use byte-widgh instructions. |
| 4858 | static const int kStrictModeBitWithinByte = |
| 4859 | (kStrictModeFunction + kCompilerHintsSmiTagSize) % kBitsPerByte; |
| 4860 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 4861 | static const int kNativeBitWithinByte = |
| 4862 | (kNative + kCompilerHintsSmiTagSize) % kBitsPerByte; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4863 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4864 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
| 4865 | static const int kStrictModeByteOffset = kCompilerHintsOffset + |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4866 | (kStrictModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 4867 | static const int kNativeByteOffset = kCompilerHintsOffset + |
| 4868 | (kNative + kCompilerHintsSmiTagSize) / kBitsPerByte; |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4869 | #elif __BYTE_ORDER == __BIG_ENDIAN |
| 4870 | static const int kStrictModeByteOffset = kCompilerHintsOffset + |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4871 | (kCompilerHintsSize - 1) - |
| 4872 | ((kStrictModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 4873 | static const int kNativeByteOffset = kCompilerHintsOffset + |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4874 | (kCompilerHintsSize - 1) - |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 4875 | ((kNative + kCompilerHintsSmiTagSize) / kBitsPerByte); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4876 | #else |
| 4877 | #error Unknown byte ordering |
| 4878 | #endif |
| 4879 | |
| 4880 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4881 | DISALLOW_IMPLICIT_CONSTRUCTORS(SharedFunctionInfo); |
| 4882 | }; |
| 4883 | |
| 4884 | |
| 4885 | // JSFunction describes JavaScript functions. |
| 4886 | class JSFunction: public JSObject { |
| 4887 | public: |
| 4888 | // [prototype_or_initial_map]: |
| 4889 | DECL_ACCESSORS(prototype_or_initial_map, Object) |
| 4890 | |
| 4891 | // [shared_function_info]: The information about the function that |
| 4892 | // can be shared by instances. |
| 4893 | DECL_ACCESSORS(shared, SharedFunctionInfo) |
| 4894 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 4895 | inline SharedFunctionInfo* unchecked_shared(); |
| 4896 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4897 | // [context]: The context for this function. |
| 4898 | inline Context* context(); |
| 4899 | inline Object* unchecked_context(); |
| 4900 | inline void set_context(Object* context); |
| 4901 | |
| 4902 | // [code]: The generated code object for this function. Executed |
| 4903 | // when the function is invoked, e.g. foo() or new foo(). See |
| 4904 | // [[Call]] and [[Construct]] description in ECMA-262, section |
| 4905 | // 8.6.2, page 27. |
| 4906 | inline Code* code(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4907 | inline void set_code(Code* code); |
| 4908 | inline void ReplaceCode(Code* code); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4909 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 4910 | inline Code* unchecked_code(); |
| 4911 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4912 | // Tells whether this function is builtin. |
| 4913 | inline bool IsBuiltin(); |
| 4914 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4915 | // Tells whether or not the function needs arguments adaption. |
| 4916 | inline bool NeedsArgumentsAdaption(); |
| 4917 | |
| 4918 | // Tells whether or not this function has been optimized. |
| 4919 | inline bool IsOptimized(); |
| 4920 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 4921 | // Tells whether or not this function can be optimized. |
| 4922 | inline bool IsOptimizable(); |
| 4923 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4924 | // Mark this function for lazy recompilation. The function will be |
| 4925 | // recompiled the next time it is executed. |
| 4926 | void MarkForLazyRecompilation(); |
| 4927 | |
| 4928 | // Tells whether or not the function is already marked for lazy |
| 4929 | // recompilation. |
| 4930 | inline bool IsMarkedForLazyRecompilation(); |
| 4931 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4932 | // Check whether or not this function is inlineable. |
| 4933 | bool IsInlineable(); |
| 4934 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4935 | // [literals]: Fixed array holding the materialized literals. |
| 4936 | // |
| 4937 | // If the function contains object, regexp or array literals, the |
| 4938 | // literals array prefix contains the object, regexp, and array |
| 4939 | // function to be used when creating these literals. This is |
| 4940 | // necessary so that we do not dynamically lookup the object, regexp |
| 4941 | // or array functions. Performing a dynamic lookup, we might end up |
| 4942 | // using the functions from a new context that we should not have |
| 4943 | // access to. |
| 4944 | DECL_ACCESSORS(literals, FixedArray) |
| 4945 | |
| 4946 | // The initial map for an object created by this constructor. |
| 4947 | inline Map* initial_map(); |
| 4948 | inline void set_initial_map(Map* value); |
| 4949 | inline bool has_initial_map(); |
| 4950 | |
| 4951 | // Get and set the prototype property on a JSFunction. If the |
| 4952 | // function has an initial map the prototype is set on the initial |
| 4953 | // map. Otherwise, the prototype is put in the initial map field |
| 4954 | // until an initial map is needed. |
| 4955 | inline bool has_prototype(); |
| 4956 | inline bool has_instance_prototype(); |
| 4957 | inline Object* prototype(); |
| 4958 | inline Object* instance_prototype(); |
| 4959 | Object* SetInstancePrototype(Object* value); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 4960 | MUST_USE_RESULT MaybeObject* SetPrototype(Object* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4961 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4962 | // After prototype is removed, it will not be created when accessed, and |
| 4963 | // [[Construct]] from this function will not be allowed. |
| 4964 | Object* RemovePrototype(); |
| 4965 | inline bool should_have_prototype(); |
| 4966 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4967 | // Accessor for this function's initial map's [[class]] |
| 4968 | // property. This is primarily used by ECMA native functions. This |
| 4969 | // method sets the class_name field of this function's initial map |
| 4970 | // to a given value. It creates an initial map if this function does |
| 4971 | // not have one. Note that this method does not copy the initial map |
| 4972 | // if it has one already, but simply replaces it with the new value. |
| 4973 | // Instances created afterwards will have a map whose [[class]] is |
| 4974 | // set to 'value', but there is no guarantees on instances created |
| 4975 | // before. |
| 4976 | Object* SetInstanceClassName(String* name); |
| 4977 | |
| 4978 | // Returns if this function has been compiled to native code yet. |
| 4979 | inline bool is_compiled(); |
| 4980 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4981 | // [next_function_link]: Field for linking functions. This list is treated as |
| 4982 | // a weak list by the GC. |
| 4983 | DECL_ACCESSORS(next_function_link, Object) |
| 4984 | |
| 4985 | // Prints the name of the function using PrintF. |
| 4986 | inline void PrintName() { |
| 4987 | PrintName(stdout); |
| 4988 | } |
| 4989 | void PrintName(FILE* out); |
| 4990 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4991 | // Casting. |
| 4992 | static inline JSFunction* cast(Object* obj); |
| 4993 | |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 4994 | // Iterates the objects, including code objects indirectly referenced |
| 4995 | // through pointers to the first instruction in the code object. |
| 4996 | void JSFunctionIterateBody(int object_size, ObjectVisitor* v); |
| 4997 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4998 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4999 | #ifdef OBJECT_PRINT |
| 5000 | inline void JSFunctionPrint() { |
| 5001 | JSFunctionPrint(stdout); |
| 5002 | } |
| 5003 | void JSFunctionPrint(FILE* out); |
| 5004 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5005 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5006 | void JSFunctionVerify(); |
| 5007 | #endif |
| 5008 | |
| 5009 | // Returns the number of allocated literals. |
| 5010 | inline int NumberOfLiterals(); |
| 5011 | |
| 5012 | // Retrieve the global context from a function's literal array. |
| 5013 | static Context* GlobalContextFromLiterals(FixedArray* literals); |
| 5014 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5015 | // Layout descriptors. The last property (from kNonWeakFieldsEndOffset to |
| 5016 | // kSize) is weak and has special handling during garbage collection. |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 5017 | static const int kCodeEntryOffset = JSObject::kHeaderSize; |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 5018 | static const int kPrototypeOrInitialMapOffset = |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 5019 | kCodeEntryOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5020 | static const int kSharedFunctionInfoOffset = |
| 5021 | kPrototypeOrInitialMapOffset + kPointerSize; |
| 5022 | static const int kContextOffset = kSharedFunctionInfoOffset + kPointerSize; |
| 5023 | static const int kLiteralsOffset = kContextOffset + kPointerSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5024 | static const int kNonWeakFieldsEndOffset = kLiteralsOffset + kPointerSize; |
| 5025 | static const int kNextFunctionLinkOffset = kNonWeakFieldsEndOffset; |
| 5026 | static const int kSize = kNextFunctionLinkOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5027 | |
| 5028 | // Layout of the literals array. |
| 5029 | static const int kLiteralsPrefixSize = 1; |
| 5030 | static const int kLiteralGlobalContextIndex = 0; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 5031 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5032 | private: |
| 5033 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunction); |
| 5034 | }; |
| 5035 | |
| 5036 | |
| 5037 | // JSGlobalProxy's prototype must be a JSGlobalObject or null, |
| 5038 | // and the prototype is hidden. JSGlobalProxy always delegates |
| 5039 | // property accesses to its prototype if the prototype is not null. |
| 5040 | // |
| 5041 | // A JSGlobalProxy can be reinitialized which will preserve its identity. |
| 5042 | // |
| 5043 | // Accessing a JSGlobalProxy requires security check. |
| 5044 | |
| 5045 | class JSGlobalProxy : public JSObject { |
| 5046 | public: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5047 | // [context]: the owner global context of this global proxy object. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5048 | // It is null value if this object is not used by any context. |
| 5049 | DECL_ACCESSORS(context, Object) |
| 5050 | |
| 5051 | // Casting. |
| 5052 | static inline JSGlobalProxy* cast(Object* obj); |
| 5053 | |
| 5054 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5055 | #ifdef OBJECT_PRINT |
| 5056 | inline void JSGlobalProxyPrint() { |
| 5057 | JSGlobalProxyPrint(stdout); |
| 5058 | } |
| 5059 | void JSGlobalProxyPrint(FILE* out); |
| 5060 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5061 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5062 | void JSGlobalProxyVerify(); |
| 5063 | #endif |
| 5064 | |
| 5065 | // Layout description. |
| 5066 | static const int kContextOffset = JSObject::kHeaderSize; |
| 5067 | static const int kSize = kContextOffset + kPointerSize; |
| 5068 | |
| 5069 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5070 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalProxy); |
| 5071 | }; |
| 5072 | |
| 5073 | |
| 5074 | // Forward declaration. |
| 5075 | class JSBuiltinsObject; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5076 | class JSGlobalPropertyCell; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5077 | |
| 5078 | // Common super class for JavaScript global objects and the special |
| 5079 | // builtins global objects. |
| 5080 | class GlobalObject: public JSObject { |
| 5081 | public: |
| 5082 | // [builtins]: the object holding the runtime routines written in JS. |
| 5083 | DECL_ACCESSORS(builtins, JSBuiltinsObject) |
| 5084 | |
| 5085 | // [global context]: the global context corresponding to this global object. |
| 5086 | DECL_ACCESSORS(global_context, Context) |
| 5087 | |
| 5088 | // [global receiver]: the global receiver object of the context |
| 5089 | DECL_ACCESSORS(global_receiver, JSObject) |
| 5090 | |
| 5091 | // Retrieve the property cell used to store a property. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5092 | JSGlobalPropertyCell* GetPropertyCell(LookupResult* result); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5093 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 5094 | // This is like GetProperty, but is used when you know the lookup won't fail |
| 5095 | // by throwing an exception. This is for the debug and builtins global |
| 5096 | // objects, where it is known which properties can be expected to be present |
| 5097 | // on the object. |
| 5098 | Object* GetPropertyNoExceptionThrown(String* key) { |
| 5099 | Object* answer = GetProperty(key)->ToObjectUnchecked(); |
| 5100 | return answer; |
| 5101 | } |
| 5102 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5103 | // 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] | 5104 | MUST_USE_RESULT MaybeObject* EnsurePropertyCell(String* name); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5105 | |
| 5106 | // Casting. |
| 5107 | static inline GlobalObject* cast(Object* obj); |
| 5108 | |
| 5109 | // Layout description. |
| 5110 | static const int kBuiltinsOffset = JSObject::kHeaderSize; |
| 5111 | static const int kGlobalContextOffset = kBuiltinsOffset + kPointerSize; |
| 5112 | static const int kGlobalReceiverOffset = kGlobalContextOffset + kPointerSize; |
| 5113 | static const int kHeaderSize = kGlobalReceiverOffset + kPointerSize; |
| 5114 | |
| 5115 | private: |
| 5116 | friend class AGCCVersionRequiresThisClassToHaveAFriendSoHereItIs; |
| 5117 | |
| 5118 | DISALLOW_IMPLICIT_CONSTRUCTORS(GlobalObject); |
| 5119 | }; |
| 5120 | |
| 5121 | |
| 5122 | // JavaScript global object. |
| 5123 | class JSGlobalObject: public GlobalObject { |
| 5124 | public: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5125 | // Casting. |
| 5126 | static inline JSGlobalObject* cast(Object* obj); |
| 5127 | |
| 5128 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5129 | #ifdef OBJECT_PRINT |
| 5130 | inline void JSGlobalObjectPrint() { |
| 5131 | JSGlobalObjectPrint(stdout); |
| 5132 | } |
| 5133 | void JSGlobalObjectPrint(FILE* out); |
| 5134 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5135 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5136 | void JSGlobalObjectVerify(); |
| 5137 | #endif |
| 5138 | |
| 5139 | // Layout description. |
| 5140 | static const int kSize = GlobalObject::kHeaderSize; |
| 5141 | |
| 5142 | private: |
| 5143 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalObject); |
| 5144 | }; |
| 5145 | |
| 5146 | |
| 5147 | // Builtins global object which holds the runtime routines written in |
| 5148 | // JavaScript. |
| 5149 | class JSBuiltinsObject: public GlobalObject { |
| 5150 | public: |
| 5151 | // Accessors for the runtime routines written in JavaScript. |
| 5152 | inline Object* javascript_builtin(Builtins::JavaScript id); |
| 5153 | inline void set_javascript_builtin(Builtins::JavaScript id, Object* value); |
| 5154 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5155 | // Accessors for code of the runtime routines written in JavaScript. |
| 5156 | inline Code* javascript_builtin_code(Builtins::JavaScript id); |
| 5157 | inline void set_javascript_builtin_code(Builtins::JavaScript id, Code* value); |
| 5158 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5159 | // Casting. |
| 5160 | static inline JSBuiltinsObject* cast(Object* obj); |
| 5161 | |
| 5162 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5163 | #ifdef OBJECT_PRINT |
| 5164 | inline void JSBuiltinsObjectPrint() { |
| 5165 | JSBuiltinsObjectPrint(stdout); |
| 5166 | } |
| 5167 | void JSBuiltinsObjectPrint(FILE* out); |
| 5168 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5169 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5170 | void JSBuiltinsObjectVerify(); |
| 5171 | #endif |
| 5172 | |
| 5173 | // Layout description. The size of the builtins object includes |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5174 | // room for two pointers per runtime routine written in javascript |
| 5175 | // (function and code object). |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5176 | static const int kJSBuiltinsCount = Builtins::id_count; |
| 5177 | static const int kJSBuiltinsOffset = GlobalObject::kHeaderSize; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5178 | static const int kJSBuiltinsCodeOffset = |
| 5179 | GlobalObject::kHeaderSize + (kJSBuiltinsCount * kPointerSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5180 | static const int kSize = |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5181 | kJSBuiltinsCodeOffset + (kJSBuiltinsCount * kPointerSize); |
| 5182 | |
| 5183 | static int OffsetOfFunctionWithId(Builtins::JavaScript id) { |
| 5184 | return kJSBuiltinsOffset + id * kPointerSize; |
| 5185 | } |
| 5186 | |
| 5187 | static int OffsetOfCodeWithId(Builtins::JavaScript id) { |
| 5188 | return kJSBuiltinsCodeOffset + id * kPointerSize; |
| 5189 | } |
| 5190 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5191 | private: |
| 5192 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSBuiltinsObject); |
| 5193 | }; |
| 5194 | |
| 5195 | |
| 5196 | // Representation for JS Wrapper objects, String, Number, Boolean, Date, etc. |
| 5197 | class JSValue: public JSObject { |
| 5198 | public: |
| 5199 | // [value]: the object being wrapped. |
| 5200 | DECL_ACCESSORS(value, Object) |
| 5201 | |
| 5202 | // Casting. |
| 5203 | static inline JSValue* cast(Object* obj); |
| 5204 | |
| 5205 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5206 | #ifdef OBJECT_PRINT |
| 5207 | inline void JSValuePrint() { |
| 5208 | JSValuePrint(stdout); |
| 5209 | } |
| 5210 | void JSValuePrint(FILE* out); |
| 5211 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5212 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5213 | void JSValueVerify(); |
| 5214 | #endif |
| 5215 | |
| 5216 | // Layout description. |
| 5217 | static const int kValueOffset = JSObject::kHeaderSize; |
| 5218 | static const int kSize = kValueOffset + kPointerSize; |
| 5219 | |
| 5220 | private: |
| 5221 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSValue); |
| 5222 | }; |
| 5223 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 5224 | |
| 5225 | // Representation of message objects used for error reporting through |
| 5226 | // the API. The messages are formatted in JavaScript so this object is |
| 5227 | // a real JavaScript object. The information used for formatting the |
| 5228 | // error messages are not directly accessible from JavaScript to |
| 5229 | // prevent leaking information to user code called during error |
| 5230 | // formatting. |
| 5231 | class JSMessageObject: public JSObject { |
| 5232 | public: |
| 5233 | // [type]: the type of error message. |
| 5234 | DECL_ACCESSORS(type, String) |
| 5235 | |
| 5236 | // [arguments]: the arguments for formatting the error message. |
| 5237 | DECL_ACCESSORS(arguments, JSArray) |
| 5238 | |
| 5239 | // [script]: the script from which the error message originated. |
| 5240 | DECL_ACCESSORS(script, Object) |
| 5241 | |
| 5242 | // [stack_trace]: the stack trace for this error message. |
| 5243 | DECL_ACCESSORS(stack_trace, Object) |
| 5244 | |
| 5245 | // [stack_frames]: an array of stack frames for this error object. |
| 5246 | DECL_ACCESSORS(stack_frames, Object) |
| 5247 | |
| 5248 | // [start_position]: the start position in the script for the error message. |
| 5249 | inline int start_position(); |
| 5250 | inline void set_start_position(int value); |
| 5251 | |
| 5252 | // [end_position]: the end position in the script for the error message. |
| 5253 | inline int end_position(); |
| 5254 | inline void set_end_position(int value); |
| 5255 | |
| 5256 | // Casting. |
| 5257 | static inline JSMessageObject* cast(Object* obj); |
| 5258 | |
| 5259 | // Dispatched behavior. |
| 5260 | #ifdef OBJECT_PRINT |
| 5261 | inline void JSMessageObjectPrint() { |
| 5262 | JSMessageObjectPrint(stdout); |
| 5263 | } |
| 5264 | void JSMessageObjectPrint(FILE* out); |
| 5265 | #endif |
| 5266 | #ifdef DEBUG |
| 5267 | void JSMessageObjectVerify(); |
| 5268 | #endif |
| 5269 | |
| 5270 | // Layout description. |
| 5271 | static const int kTypeOffset = JSObject::kHeaderSize; |
| 5272 | static const int kArgumentsOffset = kTypeOffset + kPointerSize; |
| 5273 | static const int kScriptOffset = kArgumentsOffset + kPointerSize; |
| 5274 | static const int kStackTraceOffset = kScriptOffset + kPointerSize; |
| 5275 | static const int kStackFramesOffset = kStackTraceOffset + kPointerSize; |
| 5276 | static const int kStartPositionOffset = kStackFramesOffset + kPointerSize; |
| 5277 | static const int kEndPositionOffset = kStartPositionOffset + kPointerSize; |
| 5278 | static const int kSize = kEndPositionOffset + kPointerSize; |
| 5279 | |
| 5280 | typedef FixedBodyDescriptor<HeapObject::kMapOffset, |
| 5281 | kStackFramesOffset + kPointerSize, |
| 5282 | kSize> BodyDescriptor; |
| 5283 | }; |
| 5284 | |
| 5285 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5286 | // Regular expressions |
| 5287 | // The regular expression holds a single reference to a FixedArray in |
| 5288 | // the kDataOffset field. |
| 5289 | // The FixedArray contains the following data: |
| 5290 | // - tag : type of regexp implementation (not compiled yet, atom or irregexp) |
| 5291 | // - reference to the original source string |
| 5292 | // - reference to the original flag string |
| 5293 | // If it is an atom regexp |
| 5294 | // - a reference to a literal string to search for |
| 5295 | // If it is an irregexp regexp: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5296 | // - a reference to code for ASCII inputs (bytecode or compiled), or a smi |
| 5297 | // used for tracking the last usage (used for code flushing). |
| 5298 | // - a reference to code for UC16 inputs (bytecode or compiled), or a smi |
| 5299 | // used for tracking the last usage (used for code flushing).. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5300 | // - max number of registers used by irregexp implementations. |
| 5301 | // - number of capture registers (output values) of the regexp. |
| 5302 | class JSRegExp: public JSObject { |
| 5303 | public: |
| 5304 | // Meaning of Type: |
| 5305 | // NOT_COMPILED: Initial value. No data has been stored in the JSRegExp yet. |
| 5306 | // ATOM: A simple string to match against using an indexOf operation. |
| 5307 | // IRREGEXP: Compiled with Irregexp. |
| 5308 | // IRREGEXP_NATIVE: Compiled to native code with Irregexp. |
| 5309 | enum Type { NOT_COMPILED, ATOM, IRREGEXP }; |
| 5310 | enum Flag { NONE = 0, GLOBAL = 1, IGNORE_CASE = 2, MULTILINE = 4 }; |
| 5311 | |
| 5312 | class Flags { |
| 5313 | public: |
| 5314 | explicit Flags(uint32_t value) : value_(value) { } |
| 5315 | bool is_global() { return (value_ & GLOBAL) != 0; } |
| 5316 | bool is_ignore_case() { return (value_ & IGNORE_CASE) != 0; } |
| 5317 | bool is_multiline() { return (value_ & MULTILINE) != 0; } |
| 5318 | uint32_t value() { return value_; } |
| 5319 | private: |
| 5320 | uint32_t value_; |
| 5321 | }; |
| 5322 | |
| 5323 | DECL_ACCESSORS(data, Object) |
| 5324 | |
| 5325 | inline Type TypeTag(); |
| 5326 | inline int CaptureCount(); |
| 5327 | inline Flags GetFlags(); |
| 5328 | inline String* Pattern(); |
| 5329 | inline Object* DataAt(int index); |
| 5330 | // Set implementation data after the object has been prepared. |
| 5331 | inline void SetDataAt(int index, Object* value); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5332 | |
| 5333 | // Used during GC when flushing code or setting age. |
| 5334 | inline Object* DataAtUnchecked(int index); |
| 5335 | inline void SetDataAtUnchecked(int index, Object* value, Heap* heap); |
| 5336 | inline Type TypeTagUnchecked(); |
| 5337 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5338 | static int code_index(bool is_ascii) { |
| 5339 | if (is_ascii) { |
| 5340 | return kIrregexpASCIICodeIndex; |
| 5341 | } else { |
| 5342 | return kIrregexpUC16CodeIndex; |
| 5343 | } |
| 5344 | } |
| 5345 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5346 | static int saved_code_index(bool is_ascii) { |
| 5347 | if (is_ascii) { |
| 5348 | return kIrregexpASCIICodeSavedIndex; |
| 5349 | } else { |
| 5350 | return kIrregexpUC16CodeSavedIndex; |
| 5351 | } |
| 5352 | } |
| 5353 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5354 | static inline JSRegExp* cast(Object* obj); |
| 5355 | |
| 5356 | // Dispatched behavior. |
| 5357 | #ifdef DEBUG |
| 5358 | void JSRegExpVerify(); |
| 5359 | #endif |
| 5360 | |
| 5361 | static const int kDataOffset = JSObject::kHeaderSize; |
| 5362 | static const int kSize = kDataOffset + kPointerSize; |
| 5363 | |
| 5364 | // Indices in the data array. |
| 5365 | static const int kTagIndex = 0; |
| 5366 | static const int kSourceIndex = kTagIndex + 1; |
| 5367 | static const int kFlagsIndex = kSourceIndex + 1; |
| 5368 | static const int kDataIndex = kFlagsIndex + 1; |
| 5369 | // The data fields are used in different ways depending on the |
| 5370 | // value of the tag. |
| 5371 | // Atom regexps (literal strings). |
| 5372 | static const int kAtomPatternIndex = kDataIndex; |
| 5373 | |
| 5374 | static const int kAtomDataSize = kAtomPatternIndex + 1; |
| 5375 | |
| 5376 | // Irregexp compiled code or bytecode for ASCII. If compilation |
| 5377 | // fails, this fields hold an exception object that should be |
| 5378 | // thrown if the regexp is used again. |
| 5379 | static const int kIrregexpASCIICodeIndex = kDataIndex; |
| 5380 | // Irregexp compiled code or bytecode for UC16. If compilation |
| 5381 | // fails, this fields hold an exception object that should be |
| 5382 | // thrown if the regexp is used again. |
| 5383 | static const int kIrregexpUC16CodeIndex = kDataIndex + 1; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5384 | |
| 5385 | // Saved instance of Irregexp compiled code or bytecode for ASCII that |
| 5386 | // is a potential candidate for flushing. |
| 5387 | static const int kIrregexpASCIICodeSavedIndex = kDataIndex + 2; |
| 5388 | // Saved instance of Irregexp compiled code or bytecode for UC16 that is |
| 5389 | // a potential candidate for flushing. |
| 5390 | static const int kIrregexpUC16CodeSavedIndex = kDataIndex + 3; |
| 5391 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5392 | // Maximal number of registers used by either ASCII or UC16. |
| 5393 | // Only used to check that there is enough stack space |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5394 | static const int kIrregexpMaxRegisterCountIndex = kDataIndex + 4; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5395 | // Number of captures in the compiled regexp. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5396 | static const int kIrregexpCaptureCountIndex = kDataIndex + 5; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5397 | |
| 5398 | static const int kIrregexpDataSize = kIrregexpCaptureCountIndex + 1; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 5399 | |
| 5400 | // Offsets directly into the data fixed array. |
| 5401 | static const int kDataTagOffset = |
| 5402 | FixedArray::kHeaderSize + kTagIndex * kPointerSize; |
| 5403 | static const int kDataAsciiCodeOffset = |
| 5404 | FixedArray::kHeaderSize + kIrregexpASCIICodeIndex * kPointerSize; |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 5405 | static const int kDataUC16CodeOffset = |
| 5406 | FixedArray::kHeaderSize + kIrregexpUC16CodeIndex * kPointerSize; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 5407 | static const int kIrregexpCaptureCountOffset = |
| 5408 | FixedArray::kHeaderSize + kIrregexpCaptureCountIndex * kPointerSize; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5409 | |
| 5410 | // In-object fields. |
| 5411 | static const int kSourceFieldIndex = 0; |
| 5412 | static const int kGlobalFieldIndex = 1; |
| 5413 | static const int kIgnoreCaseFieldIndex = 2; |
| 5414 | static const int kMultilineFieldIndex = 3; |
| 5415 | static const int kLastIndexFieldIndex = 4; |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 5416 | static const int kInObjectFieldCount = 5; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5417 | |
| 5418 | // The uninitialized value for a regexp code object. |
| 5419 | static const int kUninitializedValue = -1; |
| 5420 | |
| 5421 | // The compilation error value for the regexp code object. The real error |
| 5422 | // object is in the saved code field. |
| 5423 | static const int kCompilationErrorValue = -2; |
| 5424 | |
| 5425 | // When we store the sweep generation at which we moved the code from the |
| 5426 | // code index to the saved code index we mask it of to be in the [0:255] |
| 5427 | // range. |
| 5428 | static const int kCodeAgeMask = 0xff; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5429 | }; |
| 5430 | |
| 5431 | |
| 5432 | class CompilationCacheShape { |
| 5433 | public: |
| 5434 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
| 5435 | return key->IsMatch(value); |
| 5436 | } |
| 5437 | |
| 5438 | static inline uint32_t Hash(HashTableKey* key) { |
| 5439 | return key->Hash(); |
| 5440 | } |
| 5441 | |
| 5442 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
| 5443 | return key->HashForObject(object); |
| 5444 | } |
| 5445 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 5446 | MUST_USE_RESULT static MaybeObject* AsObject(HashTableKey* key) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5447 | return key->AsObject(); |
| 5448 | } |
| 5449 | |
| 5450 | static const int kPrefixSize = 0; |
| 5451 | static const int kEntrySize = 2; |
| 5452 | }; |
| 5453 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 5454 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5455 | class CompilationCacheTable: public HashTable<CompilationCacheShape, |
| 5456 | HashTableKey*> { |
| 5457 | public: |
| 5458 | // Find cached value for a string key, otherwise return null. |
| 5459 | Object* Lookup(String* src); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 5460 | Object* LookupEval(String* src, Context* context, StrictModeFlag strict_mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5461 | Object* LookupRegExp(String* source, JSRegExp::Flags flags); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 5462 | MaybeObject* Put(String* src, Object* value); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 5463 | MaybeObject* PutEval(String* src, |
| 5464 | Context* context, |
| 5465 | SharedFunctionInfo* value); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 5466 | MaybeObject* PutRegExp(String* src, JSRegExp::Flags flags, FixedArray* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5467 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5468 | // Remove given value from cache. |
| 5469 | void Remove(Object* value); |
| 5470 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5471 | static inline CompilationCacheTable* cast(Object* obj); |
| 5472 | |
| 5473 | private: |
| 5474 | DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheTable); |
| 5475 | }; |
| 5476 | |
| 5477 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5478 | class CodeCache: public Struct { |
| 5479 | public: |
| 5480 | DECL_ACCESSORS(default_cache, FixedArray) |
| 5481 | DECL_ACCESSORS(normal_type_cache, Object) |
| 5482 | |
| 5483 | // Add the code object to the cache. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 5484 | MUST_USE_RESULT MaybeObject* Update(String* name, Code* code); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5485 | |
| 5486 | // Lookup code object in the cache. Returns code object if found and undefined |
| 5487 | // if not. |
| 5488 | Object* Lookup(String* name, Code::Flags flags); |
| 5489 | |
| 5490 | // Get the internal index of a code object in the cache. Returns -1 if the |
| 5491 | // code object is not in that cache. This index can be used to later call |
| 5492 | // RemoveByIndex. The cache cannot be modified between a call to GetIndex and |
| 5493 | // RemoveByIndex. |
| 5494 | int GetIndex(Object* name, Code* code); |
| 5495 | |
| 5496 | // Remove an object from the cache with the provided internal index. |
| 5497 | void RemoveByIndex(Object* name, Code* code, int index); |
| 5498 | |
| 5499 | static inline CodeCache* cast(Object* obj); |
| 5500 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5501 | #ifdef OBJECT_PRINT |
| 5502 | inline void CodeCachePrint() { |
| 5503 | CodeCachePrint(stdout); |
| 5504 | } |
| 5505 | void CodeCachePrint(FILE* out); |
| 5506 | #endif |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5507 | #ifdef DEBUG |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5508 | void CodeCacheVerify(); |
| 5509 | #endif |
| 5510 | |
| 5511 | static const int kDefaultCacheOffset = HeapObject::kHeaderSize; |
| 5512 | static const int kNormalTypeCacheOffset = |
| 5513 | kDefaultCacheOffset + kPointerSize; |
| 5514 | static const int kSize = kNormalTypeCacheOffset + kPointerSize; |
| 5515 | |
| 5516 | private: |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 5517 | MUST_USE_RESULT MaybeObject* UpdateDefaultCache(String* name, Code* code); |
| 5518 | MUST_USE_RESULT MaybeObject* UpdateNormalTypeCache(String* name, Code* code); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5519 | Object* LookupDefaultCache(String* name, Code::Flags flags); |
| 5520 | Object* LookupNormalTypeCache(String* name, Code::Flags flags); |
| 5521 | |
| 5522 | // Code cache layout of the default cache. Elements are alternating name and |
| 5523 | // code objects for non normal load/store/call IC's. |
| 5524 | static const int kCodeCacheEntrySize = 2; |
| 5525 | static const int kCodeCacheEntryNameOffset = 0; |
| 5526 | static const int kCodeCacheEntryCodeOffset = 1; |
| 5527 | |
| 5528 | DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCache); |
| 5529 | }; |
| 5530 | |
| 5531 | |
| 5532 | class CodeCacheHashTableShape { |
| 5533 | public: |
| 5534 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
| 5535 | return key->IsMatch(value); |
| 5536 | } |
| 5537 | |
| 5538 | static inline uint32_t Hash(HashTableKey* key) { |
| 5539 | return key->Hash(); |
| 5540 | } |
| 5541 | |
| 5542 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
| 5543 | return key->HashForObject(object); |
| 5544 | } |
| 5545 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 5546 | MUST_USE_RESULT static MaybeObject* AsObject(HashTableKey* key) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5547 | return key->AsObject(); |
| 5548 | } |
| 5549 | |
| 5550 | static const int kPrefixSize = 0; |
| 5551 | static const int kEntrySize = 2; |
| 5552 | }; |
| 5553 | |
| 5554 | |
| 5555 | class CodeCacheHashTable: public HashTable<CodeCacheHashTableShape, |
| 5556 | HashTableKey*> { |
| 5557 | public: |
| 5558 | Object* Lookup(String* name, Code::Flags flags); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 5559 | MUST_USE_RESULT MaybeObject* Put(String* name, Code* code); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5560 | |
| 5561 | int GetIndex(String* name, Code::Flags flags); |
| 5562 | void RemoveByIndex(int index); |
| 5563 | |
| 5564 | static inline CodeCacheHashTable* cast(Object* obj); |
| 5565 | |
| 5566 | // Initial size of the fixed array backing the hash table. |
| 5567 | static const int kInitialSize = 64; |
| 5568 | |
| 5569 | private: |
| 5570 | DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCacheHashTable); |
| 5571 | }; |
| 5572 | |
| 5573 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 5574 | class PolymorphicCodeCache: public Struct { |
| 5575 | public: |
| 5576 | DECL_ACCESSORS(cache, Object) |
| 5577 | |
| 5578 | MUST_USE_RESULT MaybeObject* Update(MapList* maps, |
| 5579 | Code::Flags flags, |
| 5580 | Code* code); |
| 5581 | Object* Lookup(MapList* maps, Code::Flags flags); |
| 5582 | |
| 5583 | static inline PolymorphicCodeCache* cast(Object* obj); |
| 5584 | |
| 5585 | #ifdef OBJECT_PRINT |
| 5586 | inline void PolymorphicCodeCachePrint() { |
| 5587 | PolymorphicCodeCachePrint(stdout); |
| 5588 | } |
| 5589 | void PolymorphicCodeCachePrint(FILE* out); |
| 5590 | #endif |
| 5591 | #ifdef DEBUG |
| 5592 | void PolymorphicCodeCacheVerify(); |
| 5593 | #endif |
| 5594 | |
| 5595 | static const int kCacheOffset = HeapObject::kHeaderSize; |
| 5596 | static const int kSize = kCacheOffset + kPointerSize; |
| 5597 | |
| 5598 | private: |
| 5599 | DISALLOW_IMPLICIT_CONSTRUCTORS(PolymorphicCodeCache); |
| 5600 | }; |
| 5601 | |
| 5602 | |
| 5603 | class PolymorphicCodeCacheHashTable |
| 5604 | : public HashTable<CodeCacheHashTableShape, HashTableKey*> { |
| 5605 | public: |
| 5606 | Object* Lookup(MapList* maps, int code_kind); |
| 5607 | MUST_USE_RESULT MaybeObject* Put(MapList* maps, int code_kind, Code* code); |
| 5608 | |
| 5609 | static inline PolymorphicCodeCacheHashTable* cast(Object* obj); |
| 5610 | |
| 5611 | static const int kInitialSize = 64; |
| 5612 | private: |
| 5613 | DISALLOW_IMPLICIT_CONSTRUCTORS(PolymorphicCodeCacheHashTable); |
| 5614 | }; |
| 5615 | |
| 5616 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5617 | enum AllowNullsFlag {ALLOW_NULLS, DISALLOW_NULLS}; |
| 5618 | enum RobustnessFlag {ROBUST_STRING_TRAVERSAL, FAST_STRING_TRAVERSAL}; |
| 5619 | |
| 5620 | |
| 5621 | class StringHasher { |
| 5622 | public: |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 5623 | explicit inline StringHasher(int length); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5624 | |
| 5625 | // Returns true if the hash of this string can be computed without |
| 5626 | // looking at the contents. |
| 5627 | inline bool has_trivial_hash(); |
| 5628 | |
| 5629 | // Add a character to the hash and update the array index calculation. |
| 5630 | inline void AddCharacter(uc32 c); |
| 5631 | |
| 5632 | // Adds a character to the hash but does not update the array index |
| 5633 | // calculation. This can only be called when it has been verified |
| 5634 | // that the input is not an array index. |
| 5635 | inline void AddCharacterNoIndex(uc32 c); |
| 5636 | |
| 5637 | // Returns the value to store in the hash field of a string with |
| 5638 | // the given length and contents. |
| 5639 | uint32_t GetHashField(); |
| 5640 | |
| 5641 | // Returns true if the characters seen so far make up a legal array |
| 5642 | // index. |
| 5643 | bool is_array_index() { return is_array_index_; } |
| 5644 | |
| 5645 | bool is_valid() { return is_valid_; } |
| 5646 | |
| 5647 | void invalidate() { is_valid_ = false; } |
| 5648 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5649 | // Calculated hash value for a string consisting of 1 to |
| 5650 | // String::kMaxArrayIndexSize digits with no leading zeros (except "0"). |
| 5651 | // value is represented decimal value. |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 5652 | static uint32_t MakeArrayIndexHash(uint32_t value, int length); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5653 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5654 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5655 | uint32_t array_index() { |
| 5656 | ASSERT(is_array_index()); |
| 5657 | return array_index_; |
| 5658 | } |
| 5659 | |
| 5660 | inline uint32_t GetHash(); |
| 5661 | |
| 5662 | int length_; |
| 5663 | uint32_t raw_running_hash_; |
| 5664 | uint32_t array_index_; |
| 5665 | bool is_array_index_; |
| 5666 | bool is_first_char_; |
| 5667 | bool is_valid_; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5668 | friend class TwoCharHashTableKey; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5669 | }; |
| 5670 | |
| 5671 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 5672 | // Calculates string hash. |
| 5673 | template <typename schar> |
| 5674 | inline uint32_t HashSequentialString(const schar* chars, int length); |
| 5675 | |
| 5676 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5677 | // The characteristics of a string are stored in its map. Retrieving these |
| 5678 | // few bits of information is moderately expensive, involving two memory |
| 5679 | // loads where the second is dependent on the first. To improve efficiency |
| 5680 | // the shape of the string is given its own class so that it can be retrieved |
| 5681 | // once and used for several string operations. A StringShape is small enough |
| 5682 | // to be passed by value and is immutable, but be aware that flattening a |
| 5683 | // string can potentially alter its shape. Also be aware that a GC caused by |
| 5684 | // something else can alter the shape of a string due to ConsString |
| 5685 | // shortcutting. Keeping these restrictions in mind has proven to be error- |
| 5686 | // prone and so we no longer put StringShapes in variables unless there is a |
| 5687 | // concrete performance benefit at that particular point in the code. |
| 5688 | class StringShape BASE_EMBEDDED { |
| 5689 | public: |
| 5690 | inline explicit StringShape(String* s); |
| 5691 | inline explicit StringShape(Map* s); |
| 5692 | inline explicit StringShape(InstanceType t); |
| 5693 | inline bool IsSequential(); |
| 5694 | inline bool IsExternal(); |
| 5695 | inline bool IsCons(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5696 | inline bool IsExternalAscii(); |
| 5697 | inline bool IsExternalTwoByte(); |
| 5698 | inline bool IsSequentialAscii(); |
| 5699 | inline bool IsSequentialTwoByte(); |
| 5700 | inline bool IsSymbol(); |
| 5701 | inline StringRepresentationTag representation_tag(); |
| 5702 | inline uint32_t full_representation_tag(); |
| 5703 | inline uint32_t size_tag(); |
| 5704 | #ifdef DEBUG |
| 5705 | inline uint32_t type() { return type_; } |
| 5706 | inline void invalidate() { valid_ = false; } |
| 5707 | inline bool valid() { return valid_; } |
| 5708 | #else |
| 5709 | inline void invalidate() { } |
| 5710 | #endif |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 5711 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5712 | private: |
| 5713 | uint32_t type_; |
| 5714 | #ifdef DEBUG |
| 5715 | inline void set_valid() { valid_ = true; } |
| 5716 | bool valid_; |
| 5717 | #else |
| 5718 | inline void set_valid() { } |
| 5719 | #endif |
| 5720 | }; |
| 5721 | |
| 5722 | |
| 5723 | // The String abstract class captures JavaScript string values: |
| 5724 | // |
| 5725 | // Ecma-262: |
| 5726 | // 4.3.16 String Value |
| 5727 | // A string value is a member of the type String and is a finite |
| 5728 | // ordered sequence of zero or more 16-bit unsigned integer values. |
| 5729 | // |
| 5730 | // All string values have a length field. |
| 5731 | class String: public HeapObject { |
| 5732 | public: |
| 5733 | // Get and set the length of the string. |
| 5734 | inline int length(); |
| 5735 | inline void set_length(int value); |
| 5736 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5737 | // Get and set the hash field of the string. |
| 5738 | inline uint32_t hash_field(); |
| 5739 | inline void set_hash_field(uint32_t value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5740 | |
| 5741 | inline bool IsAsciiRepresentation(); |
| 5742 | inline bool IsTwoByteRepresentation(); |
| 5743 | |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 5744 | // Returns whether this string has ascii chars, i.e. all of them can |
| 5745 | // be ascii encoded. This might be the case even if the string is |
| 5746 | // two-byte. Such strings may appear when the embedder prefers |
| 5747 | // two-byte external representations even for ascii data. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5748 | // |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 5749 | // NOTE: this should be considered only a hint. False negatives are |
| 5750 | // possible. |
| 5751 | inline bool HasOnlyAsciiChars(); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5752 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5753 | // Get and set individual two byte chars in the string. |
| 5754 | inline void Set(int index, uint16_t value); |
| 5755 | // Get individual two byte char in the string. Repeated calls |
| 5756 | // to this method are not efficient unless the string is flat. |
| 5757 | inline uint16_t Get(int index); |
| 5758 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 5759 | // Try to flatten the string. Checks first inline to see if it is |
| 5760 | // necessary. Does nothing if the string is not a cons string. |
| 5761 | // Flattening allocates a sequential string with the same data as |
| 5762 | // the given string and mutates the cons string to a degenerate |
| 5763 | // form, where the first component is the new sequential string and |
| 5764 | // the second component is the empty string. If allocation fails, |
| 5765 | // this function returns a failure. If flattening succeeds, this |
| 5766 | // function returns the sequential string that is now the first |
| 5767 | // component of the cons string. |
| 5768 | // |
| 5769 | // Degenerate cons strings are handled specially by the garbage |
| 5770 | // collector (see IsShortcutCandidate). |
| 5771 | // |
| 5772 | // Use FlattenString from Handles.cc to flatten even in case an |
| 5773 | // allocation failure happens. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 5774 | inline MaybeObject* TryFlatten(PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5775 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 5776 | // Convenience function. Has exactly the same behavior as |
| 5777 | // TryFlatten(), except in the case of failure returns the original |
| 5778 | // string. |
| 5779 | inline String* TryFlattenGetString(PretenureFlag pretenure = NOT_TENURED); |
| 5780 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5781 | Vector<const char> ToAsciiVector(); |
| 5782 | Vector<const uc16> ToUC16Vector(); |
| 5783 | |
| 5784 | // Mark the string as an undetectable object. It only applies to |
| 5785 | // ascii and two byte string types. |
| 5786 | bool MarkAsUndetectable(); |
| 5787 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5788 | // Return a substring. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 5789 | MUST_USE_RESULT MaybeObject* SubString(int from, |
| 5790 | int to, |
| 5791 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5792 | |
| 5793 | // String equality operations. |
| 5794 | inline bool Equals(String* other); |
| 5795 | bool IsEqualTo(Vector<const char> str); |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 5796 | bool IsAsciiEqualTo(Vector<const char> str); |
| 5797 | bool IsTwoByteEqualTo(Vector<const uc16> str); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5798 | |
| 5799 | // Return a UTF8 representation of the string. The string is null |
| 5800 | // terminated but may optionally contain nulls. Length is returned |
| 5801 | // in length_output if length_output is not a null pointer The string |
| 5802 | // should be nearly flat, otherwise the performance of this method may |
| 5803 | // be very slow (quadratic in the length). Setting robustness_flag to |
| 5804 | // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it |
| 5805 | // handles unexpected data without causing assert failures and it does not |
| 5806 | // do any heap allocations. This is useful when printing stack traces. |
| 5807 | SmartPointer<char> ToCString(AllowNullsFlag allow_nulls, |
| 5808 | RobustnessFlag robustness_flag, |
| 5809 | int offset, |
| 5810 | int length, |
| 5811 | int* length_output = 0); |
| 5812 | SmartPointer<char> ToCString( |
| 5813 | AllowNullsFlag allow_nulls = DISALLOW_NULLS, |
| 5814 | RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL, |
| 5815 | int* length_output = 0); |
| 5816 | |
| 5817 | int Utf8Length(); |
| 5818 | |
| 5819 | // Return a 16 bit Unicode representation of the string. |
| 5820 | // The string should be nearly flat, otherwise the performance of |
| 5821 | // of this method may be very bad. Setting robustness_flag to |
| 5822 | // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it |
| 5823 | // handles unexpected data without causing assert failures and it does not |
| 5824 | // do any heap allocations. This is useful when printing stack traces. |
| 5825 | SmartPointer<uc16> ToWideCString( |
| 5826 | RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL); |
| 5827 | |
| 5828 | // Tells whether the hash code has been computed. |
| 5829 | inline bool HasHashCode(); |
| 5830 | |
| 5831 | // Returns a hash value used for the property table |
| 5832 | inline uint32_t Hash(); |
| 5833 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5834 | static uint32_t ComputeHashField(unibrow::CharacterStream* buffer, |
| 5835 | int length); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5836 | |
| 5837 | static bool ComputeArrayIndex(unibrow::CharacterStream* buffer, |
| 5838 | uint32_t* index, |
| 5839 | int length); |
| 5840 | |
| 5841 | // Externalization. |
| 5842 | bool MakeExternal(v8::String::ExternalStringResource* resource); |
| 5843 | bool MakeExternal(v8::String::ExternalAsciiStringResource* resource); |
| 5844 | |
| 5845 | // Conversion. |
| 5846 | inline bool AsArrayIndex(uint32_t* index); |
| 5847 | |
| 5848 | // Casting. |
| 5849 | static inline String* cast(Object* obj); |
| 5850 | |
| 5851 | void PrintOn(FILE* out); |
| 5852 | |
| 5853 | // For use during stack traces. Performs rudimentary sanity check. |
| 5854 | bool LooksValid(); |
| 5855 | |
| 5856 | // Dispatched behavior. |
| 5857 | void StringShortPrint(StringStream* accumulator); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5858 | #ifdef OBJECT_PRINT |
| 5859 | inline void StringPrint() { |
| 5860 | StringPrint(stdout); |
| 5861 | } |
| 5862 | void StringPrint(FILE* out); |
| 5863 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5864 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5865 | void StringVerify(); |
| 5866 | #endif |
| 5867 | inline bool IsFlat(); |
| 5868 | |
| 5869 | // Layout description. |
| 5870 | static const int kLengthOffset = HeapObject::kHeaderSize; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5871 | static const int kHashFieldOffset = kLengthOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 5872 | static const int kSize = kHashFieldOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5873 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5874 | // Maximum number of characters to consider when trying to convert a string |
| 5875 | // value into an array index. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5876 | static const int kMaxArrayIndexSize = 10; |
| 5877 | |
| 5878 | // Max ascii char code. |
| 5879 | static const int kMaxAsciiCharCode = unibrow::Utf8::kMaxOneByteChar; |
| 5880 | static const unsigned kMaxAsciiCharCodeU = unibrow::Utf8::kMaxOneByteChar; |
| 5881 | static const int kMaxUC16CharCode = 0xffff; |
| 5882 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5883 | // Minimum length for a cons string. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5884 | static const int kMinNonFlatLength = 13; |
| 5885 | |
| 5886 | // Mask constant for checking if a string has a computed hash code |
| 5887 | // and if it is an array index. The least significant bit indicates |
| 5888 | // whether a hash code has been computed. If the hash code has been |
| 5889 | // computed the 2nd bit tells whether the string can be used as an |
| 5890 | // array index. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 5891 | static const int kHashNotComputedMask = 1; |
| 5892 | static const int kIsNotArrayIndexMask = 1 << 1; |
| 5893 | static const int kNofHashBitFields = 2; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5894 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5895 | // Shift constant retrieving hash code from hash field. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 5896 | static const int kHashShift = kNofHashBitFields; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5897 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5898 | // Array index strings this short can keep their index in the hash |
| 5899 | // field. |
| 5900 | static const int kMaxCachedArrayIndexLength = 7; |
| 5901 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5902 | // For strings which are array indexes the hash value has the string length |
| 5903 | // mixed into the hash, mainly to avoid a hash value of zero which would be |
| 5904 | // 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] | 5905 | static const int kArrayIndexValueBits = 24; |
| 5906 | static const int kArrayIndexLengthBits = |
| 5907 | kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields; |
| 5908 | |
| 5909 | STATIC_CHECK((kArrayIndexLengthBits > 0)); |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 5910 | STATIC_CHECK(kMaxArrayIndexSize < (1 << kArrayIndexLengthBits)); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 5911 | |
| 5912 | static const int kArrayIndexHashLengthShift = |
| 5913 | kArrayIndexValueBits + kNofHashBitFields; |
| 5914 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5915 | static const int kArrayIndexHashMask = (1 << kArrayIndexHashLengthShift) - 1; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 5916 | |
| 5917 | static const int kArrayIndexValueMask = |
| 5918 | ((1 << kArrayIndexValueBits) - 1) << kHashShift; |
| 5919 | |
| 5920 | // Check that kMaxCachedArrayIndexLength + 1 is a power of two so we |
| 5921 | // could use a mask to test if the length of string is less than or equal to |
| 5922 | // kMaxCachedArrayIndexLength. |
| 5923 | STATIC_CHECK(IS_POWER_OF_TWO(kMaxCachedArrayIndexLength + 1)); |
| 5924 | |
| 5925 | static const int kContainsCachedArrayIndexMask = |
| 5926 | (~kMaxCachedArrayIndexLength << kArrayIndexHashLengthShift) | |
| 5927 | kIsNotArrayIndexMask; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5928 | |
| 5929 | // Value of empty hash field indicating that the hash is not computed. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 5930 | static const int kEmptyHashField = |
| 5931 | kIsNotArrayIndexMask | kHashNotComputedMask; |
| 5932 | |
| 5933 | // Value of hash field containing computed hash equal to zero. |
| 5934 | static const int kZeroHash = kIsNotArrayIndexMask; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5935 | |
| 5936 | // Maximal string length. |
| 5937 | static const int kMaxLength = (1 << (32 - 2)) - 1; |
| 5938 | |
| 5939 | // Max length for computing hash. For strings longer than this limit the |
| 5940 | // string length is used as the hash value. |
| 5941 | static const int kMaxHashCalcLength = 16383; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5942 | |
| 5943 | // Limit for truncation in short printing. |
| 5944 | static const int kMaxShortPrintLength = 1024; |
| 5945 | |
| 5946 | // Support for regular expressions. |
| 5947 | const uc16* GetTwoByteData(); |
| 5948 | const uc16* GetTwoByteData(unsigned start); |
| 5949 | |
| 5950 | // Support for StringInputBuffer |
| 5951 | static const unibrow::byte* ReadBlock(String* input, |
| 5952 | unibrow::byte* util_buffer, |
| 5953 | unsigned capacity, |
| 5954 | unsigned* remaining, |
| 5955 | unsigned* offset); |
| 5956 | static const unibrow::byte* ReadBlock(String** input, |
| 5957 | unibrow::byte* util_buffer, |
| 5958 | unsigned capacity, |
| 5959 | unsigned* remaining, |
| 5960 | unsigned* offset); |
| 5961 | |
| 5962 | // Helper function for flattening strings. |
| 5963 | template <typename sinkchar> |
| 5964 | static void WriteToFlat(String* source, |
| 5965 | sinkchar* sink, |
| 5966 | int from, |
| 5967 | int to); |
| 5968 | |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 5969 | static inline bool IsAscii(const char* chars, int length) { |
| 5970 | const char* limit = chars + length; |
| 5971 | #ifdef V8_HOST_CAN_READ_UNALIGNED |
| 5972 | ASSERT(kMaxAsciiCharCode == 0x7F); |
| 5973 | const uintptr_t non_ascii_mask = kUintptrAllBitsSet / 0xFF * 0x80; |
| 5974 | while (chars <= limit - sizeof(uintptr_t)) { |
| 5975 | if (*reinterpret_cast<const uintptr_t*>(chars) & non_ascii_mask) { |
| 5976 | return false; |
| 5977 | } |
| 5978 | chars += sizeof(uintptr_t); |
| 5979 | } |
| 5980 | #endif |
| 5981 | while (chars < limit) { |
| 5982 | if (static_cast<uint8_t>(*chars) > kMaxAsciiCharCodeU) return false; |
| 5983 | ++chars; |
| 5984 | } |
| 5985 | return true; |
| 5986 | } |
| 5987 | |
| 5988 | static inline bool IsAscii(const uc16* chars, int length) { |
| 5989 | const uc16* limit = chars + length; |
| 5990 | while (chars < limit) { |
| 5991 | if (*chars > kMaxAsciiCharCodeU) return false; |
| 5992 | ++chars; |
| 5993 | } |
| 5994 | return true; |
| 5995 | } |
| 5996 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5997 | protected: |
| 5998 | class ReadBlockBuffer { |
| 5999 | public: |
| 6000 | ReadBlockBuffer(unibrow::byte* util_buffer_, |
| 6001 | unsigned cursor_, |
| 6002 | unsigned capacity_, |
| 6003 | unsigned remaining_) : |
| 6004 | util_buffer(util_buffer_), |
| 6005 | cursor(cursor_), |
| 6006 | capacity(capacity_), |
| 6007 | remaining(remaining_) { |
| 6008 | } |
| 6009 | unibrow::byte* util_buffer; |
| 6010 | unsigned cursor; |
| 6011 | unsigned capacity; |
| 6012 | unsigned remaining; |
| 6013 | }; |
| 6014 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6015 | static inline const unibrow::byte* ReadBlock(String* input, |
| 6016 | ReadBlockBuffer* buffer, |
| 6017 | unsigned* offset, |
| 6018 | unsigned max_chars); |
| 6019 | static void ReadBlockIntoBuffer(String* input, |
| 6020 | ReadBlockBuffer* buffer, |
| 6021 | unsigned* offset_ptr, |
| 6022 | unsigned max_chars); |
| 6023 | |
| 6024 | private: |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 6025 | // Try to flatten the top level ConsString that is hiding behind this |
| 6026 | // string. This is a no-op unless the string is a ConsString. Flatten |
| 6027 | // mutates the ConsString and might return a failure. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 6028 | MUST_USE_RESULT MaybeObject* SlowTryFlatten(PretenureFlag pretenure); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 6029 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 6030 | static inline bool IsHashFieldComputed(uint32_t field); |
| 6031 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6032 | // Slow case of String::Equals. This implementation works on any strings |
| 6033 | // but it is most efficient on strings that are almost flat. |
| 6034 | bool SlowEquals(String* other); |
| 6035 | |
| 6036 | // Slow case of AsArrayIndex. |
| 6037 | bool SlowAsArrayIndex(uint32_t* index); |
| 6038 | |
| 6039 | // Compute and set the hash code. |
| 6040 | uint32_t ComputeAndSetHash(); |
| 6041 | |
| 6042 | DISALLOW_IMPLICIT_CONSTRUCTORS(String); |
| 6043 | }; |
| 6044 | |
| 6045 | |
| 6046 | // The SeqString abstract class captures sequential string values. |
| 6047 | class SeqString: public String { |
| 6048 | public: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6049 | // Casting. |
| 6050 | static inline SeqString* cast(Object* obj); |
| 6051 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6052 | private: |
| 6053 | DISALLOW_IMPLICIT_CONSTRUCTORS(SeqString); |
| 6054 | }; |
| 6055 | |
| 6056 | |
| 6057 | // The AsciiString class captures sequential ascii string objects. |
| 6058 | // Each character in the AsciiString is an ascii character. |
| 6059 | class SeqAsciiString: public SeqString { |
| 6060 | public: |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 6061 | static const bool kHasAsciiEncoding = true; |
| 6062 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6063 | // Dispatched behavior. |
| 6064 | inline uint16_t SeqAsciiStringGet(int index); |
| 6065 | inline void SeqAsciiStringSet(int index, uint16_t value); |
| 6066 | |
| 6067 | // Get the address of the characters in this string. |
| 6068 | inline Address GetCharsAddress(); |
| 6069 | |
| 6070 | inline char* GetChars(); |
| 6071 | |
| 6072 | // Casting |
| 6073 | static inline SeqAsciiString* cast(Object* obj); |
| 6074 | |
| 6075 | // Garbage collection support. This method is called by the |
| 6076 | // garbage collector to compute the actual size of an AsciiString |
| 6077 | // instance. |
| 6078 | inline int SeqAsciiStringSize(InstanceType instance_type); |
| 6079 | |
| 6080 | // Computes the size for an AsciiString instance of a given length. |
| 6081 | static int SizeFor(int length) { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 6082 | return OBJECT_POINTER_ALIGN(kHeaderSize + length * kCharSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6083 | } |
| 6084 | |
| 6085 | // Layout description. |
| 6086 | static const int kHeaderSize = String::kSize; |
| 6087 | static const int kAlignedSize = POINTER_SIZE_ALIGN(kHeaderSize); |
| 6088 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 6089 | // Maximal memory usage for a single sequential ASCII string. |
| 6090 | static const int kMaxSize = 512 * MB; |
| 6091 | // Maximal length of a single sequential ASCII string. |
| 6092 | // Q.v. String::kMaxLength which is the maximal size of concatenated strings. |
| 6093 | static const int kMaxLength = (kMaxSize - kHeaderSize); |
| 6094 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6095 | // Support for StringInputBuffer. |
| 6096 | inline void SeqAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 6097 | unsigned* offset, |
| 6098 | unsigned chars); |
| 6099 | inline const unibrow::byte* SeqAsciiStringReadBlock(unsigned* remaining, |
| 6100 | unsigned* offset, |
| 6101 | unsigned chars); |
| 6102 | |
| 6103 | private: |
| 6104 | DISALLOW_IMPLICIT_CONSTRUCTORS(SeqAsciiString); |
| 6105 | }; |
| 6106 | |
| 6107 | |
| 6108 | // The TwoByteString class captures sequential unicode string objects. |
| 6109 | // Each character in the TwoByteString is a two-byte uint16_t. |
| 6110 | class SeqTwoByteString: public SeqString { |
| 6111 | public: |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 6112 | static const bool kHasAsciiEncoding = false; |
| 6113 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6114 | // Dispatched behavior. |
| 6115 | inline uint16_t SeqTwoByteStringGet(int index); |
| 6116 | inline void SeqTwoByteStringSet(int index, uint16_t value); |
| 6117 | |
| 6118 | // Get the address of the characters in this string. |
| 6119 | inline Address GetCharsAddress(); |
| 6120 | |
| 6121 | inline uc16* GetChars(); |
| 6122 | |
| 6123 | // For regexp code. |
| 6124 | const uint16_t* SeqTwoByteStringGetData(unsigned start); |
| 6125 | |
| 6126 | // Casting |
| 6127 | static inline SeqTwoByteString* cast(Object* obj); |
| 6128 | |
| 6129 | // Garbage collection support. This method is called by the |
| 6130 | // garbage collector to compute the actual size of a TwoByteString |
| 6131 | // instance. |
| 6132 | inline int SeqTwoByteStringSize(InstanceType instance_type); |
| 6133 | |
| 6134 | // Computes the size for a TwoByteString instance of a given length. |
| 6135 | static int SizeFor(int length) { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 6136 | return OBJECT_POINTER_ALIGN(kHeaderSize + length * kShortSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6137 | } |
| 6138 | |
| 6139 | // Layout description. |
| 6140 | static const int kHeaderSize = String::kSize; |
| 6141 | static const int kAlignedSize = POINTER_SIZE_ALIGN(kHeaderSize); |
| 6142 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 6143 | // Maximal memory usage for a single sequential two-byte string. |
| 6144 | static const int kMaxSize = 512 * MB; |
| 6145 | // Maximal length of a single sequential two-byte string. |
| 6146 | // Q.v. String::kMaxLength which is the maximal size of concatenated strings. |
| 6147 | static const int kMaxLength = (kMaxSize - kHeaderSize) / sizeof(uint16_t); |
| 6148 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6149 | // Support for StringInputBuffer. |
| 6150 | inline void SeqTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 6151 | unsigned* offset_ptr, |
| 6152 | unsigned chars); |
| 6153 | |
| 6154 | private: |
| 6155 | DISALLOW_IMPLICIT_CONSTRUCTORS(SeqTwoByteString); |
| 6156 | }; |
| 6157 | |
| 6158 | |
| 6159 | // The ConsString class describes string values built by using the |
| 6160 | // addition operator on strings. A ConsString is a pair where the |
| 6161 | // first and second components are pointers to other string values. |
| 6162 | // One or both components of a ConsString can be pointers to other |
| 6163 | // ConsStrings, creating a binary tree of ConsStrings where the leaves |
| 6164 | // are non-ConsString string values. The string value represented by |
| 6165 | // a ConsString can be obtained by concatenating the leaf string |
| 6166 | // values in a left-to-right depth-first traversal of the tree. |
| 6167 | class ConsString: public String { |
| 6168 | public: |
| 6169 | // First string of the cons cell. |
| 6170 | inline String* first(); |
| 6171 | // Doesn't check that the result is a string, even in debug mode. This is |
| 6172 | // useful during GC where the mark bits confuse the checks. |
| 6173 | inline Object* unchecked_first(); |
| 6174 | inline void set_first(String* first, |
| 6175 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
| 6176 | |
| 6177 | // Second string of the cons cell. |
| 6178 | inline String* second(); |
| 6179 | // Doesn't check that the result is a string, even in debug mode. This is |
| 6180 | // useful during GC where the mark bits confuse the checks. |
| 6181 | inline Object* unchecked_second(); |
| 6182 | inline void set_second(String* second, |
| 6183 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
| 6184 | |
| 6185 | // Dispatched behavior. |
| 6186 | uint16_t ConsStringGet(int index); |
| 6187 | |
| 6188 | // Casting. |
| 6189 | static inline ConsString* cast(Object* obj); |
| 6190 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6191 | // Layout description. |
| 6192 | static const int kFirstOffset = POINTER_SIZE_ALIGN(String::kSize); |
| 6193 | static const int kSecondOffset = kFirstOffset + kPointerSize; |
| 6194 | static const int kSize = kSecondOffset + kPointerSize; |
| 6195 | |
| 6196 | // Support for StringInputBuffer. |
| 6197 | inline const unibrow::byte* ConsStringReadBlock(ReadBlockBuffer* buffer, |
| 6198 | unsigned* offset_ptr, |
| 6199 | unsigned chars); |
| 6200 | inline void ConsStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 6201 | unsigned* offset_ptr, |
| 6202 | unsigned chars); |
| 6203 | |
| 6204 | // Minimum length for a cons string. |
| 6205 | static const int kMinLength = 13; |
| 6206 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 6207 | typedef FixedBodyDescriptor<kFirstOffset, kSecondOffset + kPointerSize, kSize> |
| 6208 | BodyDescriptor; |
| 6209 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6210 | private: |
| 6211 | DISALLOW_IMPLICIT_CONSTRUCTORS(ConsString); |
| 6212 | }; |
| 6213 | |
| 6214 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6215 | // The ExternalString class describes string values that are backed by |
| 6216 | // a string resource that lies outside the V8 heap. ExternalStrings |
| 6217 | // consist of the length field common to all strings, a pointer to the |
| 6218 | // external resource. It is important to ensure (externally) that the |
| 6219 | // resource is not deallocated while the ExternalString is live in the |
| 6220 | // V8 heap. |
| 6221 | // |
| 6222 | // The API expects that all ExternalStrings are created through the |
| 6223 | // API. Therefore, ExternalStrings should not be used internally. |
| 6224 | class ExternalString: public String { |
| 6225 | public: |
| 6226 | // Casting |
| 6227 | static inline ExternalString* cast(Object* obj); |
| 6228 | |
| 6229 | // Layout description. |
| 6230 | static const int kResourceOffset = POINTER_SIZE_ALIGN(String::kSize); |
| 6231 | static const int kSize = kResourceOffset + kPointerSize; |
| 6232 | |
| 6233 | STATIC_CHECK(kResourceOffset == Internals::kStringResourceOffset); |
| 6234 | |
| 6235 | private: |
| 6236 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalString); |
| 6237 | }; |
| 6238 | |
| 6239 | |
| 6240 | // The ExternalAsciiString class is an external string backed by an |
| 6241 | // ASCII string. |
| 6242 | class ExternalAsciiString: public ExternalString { |
| 6243 | public: |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 6244 | static const bool kHasAsciiEncoding = true; |
| 6245 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6246 | typedef v8::String::ExternalAsciiStringResource Resource; |
| 6247 | |
| 6248 | // The underlying resource. |
| 6249 | inline Resource* resource(); |
| 6250 | inline void set_resource(Resource* buffer); |
| 6251 | |
| 6252 | // Dispatched behavior. |
| 6253 | uint16_t ExternalAsciiStringGet(int index); |
| 6254 | |
| 6255 | // Casting. |
| 6256 | static inline ExternalAsciiString* cast(Object* obj); |
| 6257 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 6258 | // Garbage collection support. |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 6259 | inline void ExternalAsciiStringIterateBody(ObjectVisitor* v); |
| 6260 | |
| 6261 | template<typename StaticVisitor> |
| 6262 | inline void ExternalAsciiStringIterateBody(); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 6263 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6264 | // Support for StringInputBuffer. |
| 6265 | const unibrow::byte* ExternalAsciiStringReadBlock(unsigned* remaining, |
| 6266 | unsigned* offset, |
| 6267 | unsigned chars); |
| 6268 | inline void ExternalAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 6269 | unsigned* offset, |
| 6270 | unsigned chars); |
| 6271 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6272 | private: |
| 6273 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalAsciiString); |
| 6274 | }; |
| 6275 | |
| 6276 | |
| 6277 | // The ExternalTwoByteString class is an external string backed by a UTF-16 |
| 6278 | // encoded string. |
| 6279 | class ExternalTwoByteString: public ExternalString { |
| 6280 | public: |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 6281 | static const bool kHasAsciiEncoding = false; |
| 6282 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6283 | typedef v8::String::ExternalStringResource Resource; |
| 6284 | |
| 6285 | // The underlying string resource. |
| 6286 | inline Resource* resource(); |
| 6287 | inline void set_resource(Resource* buffer); |
| 6288 | |
| 6289 | // Dispatched behavior. |
| 6290 | uint16_t ExternalTwoByteStringGet(int index); |
| 6291 | |
| 6292 | // For regexp code. |
| 6293 | const uint16_t* ExternalTwoByteStringGetData(unsigned start); |
| 6294 | |
| 6295 | // Casting. |
| 6296 | static inline ExternalTwoByteString* cast(Object* obj); |
| 6297 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 6298 | // Garbage collection support. |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 6299 | inline void ExternalTwoByteStringIterateBody(ObjectVisitor* v); |
| 6300 | |
| 6301 | template<typename StaticVisitor> |
| 6302 | inline void ExternalTwoByteStringIterateBody(); |
| 6303 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 6304 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6305 | // Support for StringInputBuffer. |
| 6306 | void ExternalTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 6307 | unsigned* offset_ptr, |
| 6308 | unsigned chars); |
| 6309 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6310 | private: |
| 6311 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalTwoByteString); |
| 6312 | }; |
| 6313 | |
| 6314 | |
| 6315 | // Utility superclass for stack-allocated objects that must be updated |
| 6316 | // on gc. It provides two ways for the gc to update instances, either |
| 6317 | // iterating or updating after gc. |
| 6318 | class Relocatable BASE_EMBEDDED { |
| 6319 | public: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 6320 | explicit inline Relocatable(Isolate* isolate); |
| 6321 | inline virtual ~Relocatable(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6322 | virtual void IterateInstance(ObjectVisitor* v) { } |
| 6323 | virtual void PostGarbageCollection() { } |
| 6324 | |
| 6325 | static void PostGarbageCollectionProcessing(); |
| 6326 | static int ArchiveSpacePerThread(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6327 | static char* ArchiveState(Isolate* isolate, char* to); |
| 6328 | static char* RestoreState(Isolate* isolate, char* from); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6329 | static void Iterate(ObjectVisitor* v); |
| 6330 | static void Iterate(ObjectVisitor* v, Relocatable* top); |
| 6331 | static char* Iterate(ObjectVisitor* v, char* t); |
| 6332 | private: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 6333 | Isolate* isolate_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6334 | Relocatable* prev_; |
| 6335 | }; |
| 6336 | |
| 6337 | |
| 6338 | // A flat string reader provides random access to the contents of a |
| 6339 | // string independent of the character width of the string. The handle |
| 6340 | // must be valid as long as the reader is being used. |
| 6341 | class FlatStringReader : public Relocatable { |
| 6342 | public: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 6343 | FlatStringReader(Isolate* isolate, Handle<String> str); |
| 6344 | FlatStringReader(Isolate* isolate, Vector<const char> input); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6345 | void PostGarbageCollection(); |
| 6346 | inline uc32 Get(int index); |
| 6347 | int length() { return length_; } |
| 6348 | private: |
| 6349 | String** str_; |
| 6350 | bool is_ascii_; |
| 6351 | int length_; |
| 6352 | const void* start_; |
| 6353 | }; |
| 6354 | |
| 6355 | |
| 6356 | // Note that StringInputBuffers are not valid across a GC! To fix this |
| 6357 | // it would have to store a String Handle instead of a String* and |
| 6358 | // AsciiStringReadBlock would have to be modified to use memcpy. |
| 6359 | // |
| 6360 | // StringInputBuffer is able to traverse any string regardless of how |
| 6361 | // deeply nested a sequence of ConsStrings it is made of. However, |
| 6362 | // performance will be better if deep strings are flattened before they |
| 6363 | // are traversed. Since flattening requires memory allocation this is |
| 6364 | // not always desirable, however (esp. in debugging situations). |
| 6365 | class StringInputBuffer: public unibrow::InputBuffer<String, String*, 1024> { |
| 6366 | public: |
| 6367 | virtual void Seek(unsigned pos); |
| 6368 | inline StringInputBuffer(): unibrow::InputBuffer<String, String*, 1024>() {} |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 6369 | explicit inline StringInputBuffer(String* backing): |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6370 | unibrow::InputBuffer<String, String*, 1024>(backing) {} |
| 6371 | }; |
| 6372 | |
| 6373 | |
| 6374 | class SafeStringInputBuffer |
| 6375 | : public unibrow::InputBuffer<String, String**, 256> { |
| 6376 | public: |
| 6377 | virtual void Seek(unsigned pos); |
| 6378 | inline SafeStringInputBuffer() |
| 6379 | : unibrow::InputBuffer<String, String**, 256>() {} |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 6380 | explicit inline SafeStringInputBuffer(String** backing) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6381 | : unibrow::InputBuffer<String, String**, 256>(backing) {} |
| 6382 | }; |
| 6383 | |
| 6384 | |
| 6385 | template <typename T> |
| 6386 | class VectorIterator { |
| 6387 | public: |
| 6388 | VectorIterator(T* d, int l) : data_(Vector<const T>(d, l)), index_(0) { } |
| 6389 | explicit VectorIterator(Vector<const T> data) : data_(data), index_(0) { } |
| 6390 | T GetNext() { return data_[index_++]; } |
| 6391 | bool has_more() { return index_ < data_.length(); } |
| 6392 | private: |
| 6393 | Vector<const T> data_; |
| 6394 | int index_; |
| 6395 | }; |
| 6396 | |
| 6397 | |
| 6398 | // The Oddball describes objects null, undefined, true, and false. |
| 6399 | class Oddball: public HeapObject { |
| 6400 | public: |
| 6401 | // [to_string]: Cached to_string computed at startup. |
| 6402 | DECL_ACCESSORS(to_string, String) |
| 6403 | |
| 6404 | // [to_number]: Cached to_number computed at startup. |
| 6405 | DECL_ACCESSORS(to_number, Object) |
| 6406 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 6407 | inline byte kind(); |
| 6408 | inline void set_kind(byte kind); |
| 6409 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6410 | // Casting. |
| 6411 | static inline Oddball* cast(Object* obj); |
| 6412 | |
| 6413 | // Dispatched behavior. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6414 | #ifdef DEBUG |
| 6415 | void OddballVerify(); |
| 6416 | #endif |
| 6417 | |
| 6418 | // Initialize the fields. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 6419 | MUST_USE_RESULT MaybeObject* Initialize(const char* to_string, |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 6420 | Object* to_number, |
| 6421 | byte kind); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6422 | |
| 6423 | // Layout description. |
| 6424 | static const int kToStringOffset = HeapObject::kHeaderSize; |
| 6425 | static const int kToNumberOffset = kToStringOffset + kPointerSize; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 6426 | static const int kKindOffset = kToNumberOffset + kPointerSize; |
| 6427 | static const int kSize = kKindOffset + kPointerSize; |
| 6428 | |
| 6429 | static const byte kFalse = 0; |
| 6430 | static const byte kTrue = 1; |
| 6431 | static const byte kNotBooleanMask = ~1; |
| 6432 | static const byte kTheHole = 2; |
| 6433 | static const byte kNull = 3; |
| 6434 | static const byte kArgumentMarker = 4; |
| 6435 | static const byte kUndefined = 5; |
| 6436 | static const byte kOther = 6; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6437 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 6438 | typedef FixedBodyDescriptor<kToStringOffset, |
| 6439 | kToNumberOffset + kPointerSize, |
| 6440 | kSize> BodyDescriptor; |
| 6441 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6442 | private: |
| 6443 | DISALLOW_IMPLICIT_CONSTRUCTORS(Oddball); |
| 6444 | }; |
| 6445 | |
| 6446 | |
| 6447 | class JSGlobalPropertyCell: public HeapObject { |
| 6448 | public: |
| 6449 | // [value]: value of the global property. |
| 6450 | DECL_ACCESSORS(value, Object) |
| 6451 | |
| 6452 | // Casting. |
| 6453 | static inline JSGlobalPropertyCell* cast(Object* obj); |
| 6454 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6455 | #ifdef DEBUG |
| 6456 | void JSGlobalPropertyCellVerify(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6457 | #endif |
| 6458 | #ifdef OBJECT_PRINT |
| 6459 | inline void JSGlobalPropertyCellPrint() { |
| 6460 | JSGlobalPropertyCellPrint(stdout); |
| 6461 | } |
| 6462 | void JSGlobalPropertyCellPrint(FILE* out); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6463 | #endif |
| 6464 | |
| 6465 | // Layout description. |
| 6466 | static const int kValueOffset = HeapObject::kHeaderSize; |
| 6467 | static const int kSize = kValueOffset + kPointerSize; |
| 6468 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 6469 | typedef FixedBodyDescriptor<kValueOffset, |
| 6470 | kValueOffset + kPointerSize, |
| 6471 | kSize> BodyDescriptor; |
| 6472 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 6473 | // Returns the isolate/heap this cell object belongs to. |
| 6474 | inline Isolate* isolate(); |
| 6475 | inline Heap* heap(); |
| 6476 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6477 | private: |
| 6478 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalPropertyCell); |
| 6479 | }; |
| 6480 | |
| 6481 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6482 | // The JSProxy describes EcmaScript Harmony proxies |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 6483 | class JSProxy: public JSReceiver { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6484 | public: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6485 | // [handler]: The handler property. |
| 6486 | DECL_ACCESSORS(handler, Object) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6487 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 6488 | // [padding]: The padding slot (unused, see below). |
| 6489 | DECL_ACCESSORS(padding, Object) |
| 6490 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6491 | // Casting. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6492 | static inline JSProxy* cast(Object* obj); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6493 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 6494 | bool HasPropertyWithHandler(String* name); |
| 6495 | |
| 6496 | MUST_USE_RESULT MaybeObject* SetPropertyWithHandler( |
| 6497 | String* name, |
| 6498 | Object* value, |
| 6499 | PropertyAttributes attributes, |
| 6500 | StrictModeFlag strict_mode); |
| 6501 | |
| 6502 | MUST_USE_RESULT MaybeObject* DeletePropertyWithHandler( |
| 6503 | String* name, |
| 6504 | DeleteMode mode); |
| 6505 | |
| 6506 | MUST_USE_RESULT PropertyAttributes GetPropertyAttributeWithHandler( |
| 6507 | JSReceiver* receiver, |
| 6508 | String* name, |
| 6509 | bool* has_exception); |
| 6510 | |
| 6511 | // Turn this into an (empty) JSObject. |
| 6512 | void Fix(); |
| 6513 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6514 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6515 | #ifdef OBJECT_PRINT |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6516 | inline void JSProxyPrint() { |
| 6517 | JSProxyPrint(stdout); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6518 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6519 | void JSProxyPrint(FILE* out); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6520 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6521 | #ifdef DEBUG |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6522 | void JSProxyVerify(); |
| 6523 | #endif |
| 6524 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 6525 | // Layout description. We add padding so that a proxy has the same |
| 6526 | // size as a virgin JSObject. This is essential for becoming a JSObject |
| 6527 | // upon freeze. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6528 | static const int kHandlerOffset = HeapObject::kHeaderSize; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 6529 | static const int kPaddingOffset = kHandlerOffset + kPointerSize; |
| 6530 | static const int kSize = kPaddingOffset + kPointerSize; |
| 6531 | |
| 6532 | STATIC_CHECK(kSize == JSObject::kHeaderSize); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6533 | |
| 6534 | typedef FixedBodyDescriptor<kHandlerOffset, |
| 6535 | kHandlerOffset + kPointerSize, |
| 6536 | kSize> BodyDescriptor; |
| 6537 | |
| 6538 | private: |
| 6539 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSProxy); |
| 6540 | }; |
| 6541 | |
| 6542 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 6543 | // TODO(rossberg): Only a stub for now. |
| 6544 | class JSFunctionProxy: public JSProxy { |
| 6545 | public: |
| 6546 | // Casting. |
| 6547 | static inline JSFunctionProxy* cast(Object* obj); |
| 6548 | |
| 6549 | private: |
| 6550 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunctionProxy); |
| 6551 | }; |
| 6552 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6553 | |
| 6554 | // Foreign describes objects pointing from JavaScript to C structures. |
| 6555 | // Since they cannot contain references to JS HeapObjects they can be |
| 6556 | // placed in old_data_space. |
| 6557 | class Foreign: public HeapObject { |
| 6558 | public: |
| 6559 | // [address]: field containing the address. |
| 6560 | inline Address address(); |
| 6561 | inline void set_address(Address value); |
| 6562 | |
| 6563 | // Casting. |
| 6564 | static inline Foreign* cast(Object* obj); |
| 6565 | |
| 6566 | // Dispatched behavior. |
| 6567 | inline void ForeignIterateBody(ObjectVisitor* v); |
| 6568 | |
| 6569 | template<typename StaticVisitor> |
| 6570 | inline void ForeignIterateBody(); |
| 6571 | |
| 6572 | #ifdef OBJECT_PRINT |
| 6573 | inline void ForeignPrint() { |
| 6574 | ForeignPrint(stdout); |
| 6575 | } |
| 6576 | void ForeignPrint(FILE* out); |
| 6577 | #endif |
| 6578 | #ifdef DEBUG |
| 6579 | void ForeignVerify(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6580 | #endif |
| 6581 | |
| 6582 | // Layout description. |
| 6583 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6584 | static const int kAddressOffset = HeapObject::kHeaderSize; |
| 6585 | static const int kSize = kAddressOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6586 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6587 | STATIC_CHECK(kAddressOffset == Internals::kForeignAddressOffset); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6588 | |
| 6589 | private: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6590 | DISALLOW_IMPLICIT_CONSTRUCTORS(Foreign); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6591 | }; |
| 6592 | |
| 6593 | |
| 6594 | // The JSArray describes JavaScript Arrays |
| 6595 | // Such an array can be in one of two modes: |
| 6596 | // - fast, backing storage is a FixedArray and length <= elements.length(); |
| 6597 | // Please note: push and pop can be used to grow and shrink the array. |
| 6598 | // - slow, backing storage is a HashTable with numbers as keys. |
| 6599 | class JSArray: public JSObject { |
| 6600 | public: |
| 6601 | // [length]: The length property. |
| 6602 | DECL_ACCESSORS(length, Object) |
| 6603 | |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 6604 | // Overload the length setter to skip write barrier when the length |
| 6605 | // is set to a smi. This matches the set function on FixedArray. |
| 6606 | inline void set_length(Smi* length); |
| 6607 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 6608 | MUST_USE_RESULT MaybeObject* JSArrayUpdateLengthFromIndex(uint32_t index, |
| 6609 | Object* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6610 | |
| 6611 | // Initialize the array with the given capacity. The function may |
| 6612 | // fail due to out-of-memory situations, but only if the requested |
| 6613 | // capacity is non-zero. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 6614 | MUST_USE_RESULT MaybeObject* Initialize(int capacity); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6615 | |
| 6616 | // Set the content of the array to the content of storage. |
| 6617 | inline void SetContent(FixedArray* storage); |
| 6618 | |
| 6619 | // Casting. |
| 6620 | static inline JSArray* cast(Object* obj); |
| 6621 | |
| 6622 | // Uses handles. Ensures that the fixed array backing the JSArray has at |
| 6623 | // least the stated size. |
| 6624 | inline void EnsureSize(int minimum_size_of_backing_fixed_array); |
| 6625 | |
| 6626 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6627 | #ifdef OBJECT_PRINT |
| 6628 | inline void JSArrayPrint() { |
| 6629 | JSArrayPrint(stdout); |
| 6630 | } |
| 6631 | void JSArrayPrint(FILE* out); |
| 6632 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6633 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6634 | void JSArrayVerify(); |
| 6635 | #endif |
| 6636 | |
| 6637 | // Number of element slots to pre-allocate for an empty array. |
| 6638 | static const int kPreallocatedArrayElements = 4; |
| 6639 | |
| 6640 | // Layout description. |
| 6641 | static const int kLengthOffset = JSObject::kHeaderSize; |
| 6642 | static const int kSize = kLengthOffset + kPointerSize; |
| 6643 | |
| 6644 | private: |
| 6645 | // Expand the fixed array backing of a fast-case JSArray to at least |
| 6646 | // the requested size. |
| 6647 | void Expand(int minimum_size_of_backing_fixed_array); |
| 6648 | |
| 6649 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSArray); |
| 6650 | }; |
| 6651 | |
| 6652 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 6653 | // JSRegExpResult is just a JSArray with a specific initial map. |
| 6654 | // This initial map adds in-object properties for "index" and "input" |
| 6655 | // properties, as assigned by RegExp.prototype.exec, which allows |
| 6656 | // faster creation of RegExp exec results. |
| 6657 | // This class just holds constants used when creating the result. |
| 6658 | // After creation the result must be treated as a JSArray in all regards. |
| 6659 | class JSRegExpResult: public JSArray { |
| 6660 | public: |
| 6661 | // Offsets of object fields. |
| 6662 | static const int kIndexOffset = JSArray::kSize; |
| 6663 | static const int kInputOffset = kIndexOffset + kPointerSize; |
| 6664 | static const int kSize = kInputOffset + kPointerSize; |
| 6665 | // Indices of in-object properties. |
| 6666 | static const int kIndexIndex = 0; |
| 6667 | static const int kInputIndex = 1; |
| 6668 | private: |
| 6669 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSRegExpResult); |
| 6670 | }; |
| 6671 | |
| 6672 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6673 | // An accessor must have a getter, but can have no setter. |
| 6674 | // |
| 6675 | // When setting a property, V8 searches accessors in prototypes. |
| 6676 | // If an accessor was found and it does not have a setter, |
| 6677 | // the request is ignored. |
| 6678 | // |
| 6679 | // If the accessor in the prototype has the READ_ONLY property attribute, then |
| 6680 | // a new value is added to the local object when the property is set. |
| 6681 | // This shadows the accessor in the prototype. |
| 6682 | class AccessorInfo: public Struct { |
| 6683 | public: |
| 6684 | DECL_ACCESSORS(getter, Object) |
| 6685 | DECL_ACCESSORS(setter, Object) |
| 6686 | DECL_ACCESSORS(data, Object) |
| 6687 | DECL_ACCESSORS(name, Object) |
| 6688 | DECL_ACCESSORS(flag, Smi) |
| 6689 | |
| 6690 | inline bool all_can_read(); |
| 6691 | inline void set_all_can_read(bool value); |
| 6692 | |
| 6693 | inline bool all_can_write(); |
| 6694 | inline void set_all_can_write(bool value); |
| 6695 | |
| 6696 | inline bool prohibits_overwriting(); |
| 6697 | inline void set_prohibits_overwriting(bool value); |
| 6698 | |
| 6699 | inline PropertyAttributes property_attributes(); |
| 6700 | inline void set_property_attributes(PropertyAttributes attributes); |
| 6701 | |
| 6702 | static inline AccessorInfo* cast(Object* obj); |
| 6703 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6704 | #ifdef OBJECT_PRINT |
| 6705 | inline void AccessorInfoPrint() { |
| 6706 | AccessorInfoPrint(stdout); |
| 6707 | } |
| 6708 | void AccessorInfoPrint(FILE* out); |
| 6709 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6710 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6711 | void AccessorInfoVerify(); |
| 6712 | #endif |
| 6713 | |
| 6714 | static const int kGetterOffset = HeapObject::kHeaderSize; |
| 6715 | static const int kSetterOffset = kGetterOffset + kPointerSize; |
| 6716 | static const int kDataOffset = kSetterOffset + kPointerSize; |
| 6717 | static const int kNameOffset = kDataOffset + kPointerSize; |
| 6718 | static const int kFlagOffset = kNameOffset + kPointerSize; |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 6719 | static const int kSize = kFlagOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6720 | |
| 6721 | private: |
| 6722 | // Bit positions in flag. |
| 6723 | static const int kAllCanReadBit = 0; |
| 6724 | static const int kAllCanWriteBit = 1; |
| 6725 | static const int kProhibitsOverwritingBit = 2; |
| 6726 | class AttributesField: public BitField<PropertyAttributes, 3, 3> {}; |
| 6727 | |
| 6728 | DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorInfo); |
| 6729 | }; |
| 6730 | |
| 6731 | |
| 6732 | class AccessCheckInfo: public Struct { |
| 6733 | public: |
| 6734 | DECL_ACCESSORS(named_callback, Object) |
| 6735 | DECL_ACCESSORS(indexed_callback, Object) |
| 6736 | DECL_ACCESSORS(data, Object) |
| 6737 | |
| 6738 | static inline AccessCheckInfo* cast(Object* obj); |
| 6739 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6740 | #ifdef OBJECT_PRINT |
| 6741 | inline void AccessCheckInfoPrint() { |
| 6742 | AccessCheckInfoPrint(stdout); |
| 6743 | } |
| 6744 | void AccessCheckInfoPrint(FILE* out); |
| 6745 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6746 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6747 | void AccessCheckInfoVerify(); |
| 6748 | #endif |
| 6749 | |
| 6750 | static const int kNamedCallbackOffset = HeapObject::kHeaderSize; |
| 6751 | static const int kIndexedCallbackOffset = kNamedCallbackOffset + kPointerSize; |
| 6752 | static const int kDataOffset = kIndexedCallbackOffset + kPointerSize; |
| 6753 | static const int kSize = kDataOffset + kPointerSize; |
| 6754 | |
| 6755 | private: |
| 6756 | DISALLOW_IMPLICIT_CONSTRUCTORS(AccessCheckInfo); |
| 6757 | }; |
| 6758 | |
| 6759 | |
| 6760 | class InterceptorInfo: public Struct { |
| 6761 | public: |
| 6762 | DECL_ACCESSORS(getter, Object) |
| 6763 | DECL_ACCESSORS(setter, Object) |
| 6764 | DECL_ACCESSORS(query, Object) |
| 6765 | DECL_ACCESSORS(deleter, Object) |
| 6766 | DECL_ACCESSORS(enumerator, Object) |
| 6767 | DECL_ACCESSORS(data, Object) |
| 6768 | |
| 6769 | static inline InterceptorInfo* cast(Object* obj); |
| 6770 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6771 | #ifdef OBJECT_PRINT |
| 6772 | inline void InterceptorInfoPrint() { |
| 6773 | InterceptorInfoPrint(stdout); |
| 6774 | } |
| 6775 | void InterceptorInfoPrint(FILE* out); |
| 6776 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6777 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6778 | void InterceptorInfoVerify(); |
| 6779 | #endif |
| 6780 | |
| 6781 | static const int kGetterOffset = HeapObject::kHeaderSize; |
| 6782 | static const int kSetterOffset = kGetterOffset + kPointerSize; |
| 6783 | static const int kQueryOffset = kSetterOffset + kPointerSize; |
| 6784 | static const int kDeleterOffset = kQueryOffset + kPointerSize; |
| 6785 | static const int kEnumeratorOffset = kDeleterOffset + kPointerSize; |
| 6786 | static const int kDataOffset = kEnumeratorOffset + kPointerSize; |
| 6787 | static const int kSize = kDataOffset + kPointerSize; |
| 6788 | |
| 6789 | private: |
| 6790 | DISALLOW_IMPLICIT_CONSTRUCTORS(InterceptorInfo); |
| 6791 | }; |
| 6792 | |
| 6793 | |
| 6794 | class CallHandlerInfo: public Struct { |
| 6795 | public: |
| 6796 | DECL_ACCESSORS(callback, Object) |
| 6797 | DECL_ACCESSORS(data, Object) |
| 6798 | |
| 6799 | static inline CallHandlerInfo* cast(Object* obj); |
| 6800 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6801 | #ifdef OBJECT_PRINT |
| 6802 | inline void CallHandlerInfoPrint() { |
| 6803 | CallHandlerInfoPrint(stdout); |
| 6804 | } |
| 6805 | void CallHandlerInfoPrint(FILE* out); |
| 6806 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6807 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6808 | void CallHandlerInfoVerify(); |
| 6809 | #endif |
| 6810 | |
| 6811 | static const int kCallbackOffset = HeapObject::kHeaderSize; |
| 6812 | static const int kDataOffset = kCallbackOffset + kPointerSize; |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 6813 | static const int kSize = kDataOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6814 | |
| 6815 | private: |
| 6816 | DISALLOW_IMPLICIT_CONSTRUCTORS(CallHandlerInfo); |
| 6817 | }; |
| 6818 | |
| 6819 | |
| 6820 | class TemplateInfo: public Struct { |
| 6821 | public: |
| 6822 | DECL_ACCESSORS(tag, Object) |
| 6823 | DECL_ACCESSORS(property_list, Object) |
| 6824 | |
| 6825 | #ifdef DEBUG |
| 6826 | void TemplateInfoVerify(); |
| 6827 | #endif |
| 6828 | |
| 6829 | static const int kTagOffset = HeapObject::kHeaderSize; |
| 6830 | static const int kPropertyListOffset = kTagOffset + kPointerSize; |
| 6831 | static const int kHeaderSize = kPropertyListOffset + kPointerSize; |
| 6832 | protected: |
| 6833 | friend class AGCCVersionRequiresThisClassToHaveAFriendSoHereItIs; |
| 6834 | DISALLOW_IMPLICIT_CONSTRUCTORS(TemplateInfo); |
| 6835 | }; |
| 6836 | |
| 6837 | |
| 6838 | class FunctionTemplateInfo: public TemplateInfo { |
| 6839 | public: |
| 6840 | DECL_ACCESSORS(serial_number, Object) |
| 6841 | DECL_ACCESSORS(call_code, Object) |
| 6842 | DECL_ACCESSORS(property_accessors, Object) |
| 6843 | DECL_ACCESSORS(prototype_template, Object) |
| 6844 | DECL_ACCESSORS(parent_template, Object) |
| 6845 | DECL_ACCESSORS(named_property_handler, Object) |
| 6846 | DECL_ACCESSORS(indexed_property_handler, Object) |
| 6847 | DECL_ACCESSORS(instance_template, Object) |
| 6848 | DECL_ACCESSORS(class_name, Object) |
| 6849 | DECL_ACCESSORS(signature, Object) |
| 6850 | DECL_ACCESSORS(instance_call_handler, Object) |
| 6851 | DECL_ACCESSORS(access_check_info, Object) |
| 6852 | DECL_ACCESSORS(flag, Smi) |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 6853 | DECL_ACCESSORS(prototype_attributes, Smi) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6854 | |
| 6855 | // Following properties use flag bits. |
| 6856 | DECL_BOOLEAN_ACCESSORS(hidden_prototype) |
| 6857 | DECL_BOOLEAN_ACCESSORS(undetectable) |
| 6858 | // If the bit is set, object instances created by this function |
| 6859 | // requires access check. |
| 6860 | DECL_BOOLEAN_ACCESSORS(needs_access_check) |
| 6861 | |
| 6862 | static inline FunctionTemplateInfo* cast(Object* obj); |
| 6863 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6864 | #ifdef OBJECT_PRINT |
| 6865 | inline void FunctionTemplateInfoPrint() { |
| 6866 | FunctionTemplateInfoPrint(stdout); |
| 6867 | } |
| 6868 | void FunctionTemplateInfoPrint(FILE* out); |
| 6869 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6870 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6871 | void FunctionTemplateInfoVerify(); |
| 6872 | #endif |
| 6873 | |
| 6874 | static const int kSerialNumberOffset = TemplateInfo::kHeaderSize; |
| 6875 | static const int kCallCodeOffset = kSerialNumberOffset + kPointerSize; |
| 6876 | static const int kPropertyAccessorsOffset = kCallCodeOffset + kPointerSize; |
| 6877 | static const int kPrototypeTemplateOffset = |
| 6878 | kPropertyAccessorsOffset + kPointerSize; |
| 6879 | static const int kParentTemplateOffset = |
| 6880 | kPrototypeTemplateOffset + kPointerSize; |
| 6881 | static const int kNamedPropertyHandlerOffset = |
| 6882 | kParentTemplateOffset + kPointerSize; |
| 6883 | static const int kIndexedPropertyHandlerOffset = |
| 6884 | kNamedPropertyHandlerOffset + kPointerSize; |
| 6885 | static const int kInstanceTemplateOffset = |
| 6886 | kIndexedPropertyHandlerOffset + kPointerSize; |
| 6887 | static const int kClassNameOffset = kInstanceTemplateOffset + kPointerSize; |
| 6888 | static const int kSignatureOffset = kClassNameOffset + kPointerSize; |
| 6889 | static const int kInstanceCallHandlerOffset = kSignatureOffset + kPointerSize; |
| 6890 | static const int kAccessCheckInfoOffset = |
| 6891 | kInstanceCallHandlerOffset + kPointerSize; |
| 6892 | static const int kFlagOffset = kAccessCheckInfoOffset + kPointerSize; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 6893 | static const int kPrototypeAttributesOffset = kFlagOffset + kPointerSize; |
| 6894 | static const int kSize = kPrototypeAttributesOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6895 | |
| 6896 | private: |
| 6897 | // Bit position in the flag, from least significant bit position. |
| 6898 | static const int kHiddenPrototypeBit = 0; |
| 6899 | static const int kUndetectableBit = 1; |
| 6900 | static const int kNeedsAccessCheckBit = 2; |
| 6901 | |
| 6902 | DISALLOW_IMPLICIT_CONSTRUCTORS(FunctionTemplateInfo); |
| 6903 | }; |
| 6904 | |
| 6905 | |
| 6906 | class ObjectTemplateInfo: public TemplateInfo { |
| 6907 | public: |
| 6908 | DECL_ACCESSORS(constructor, Object) |
| 6909 | DECL_ACCESSORS(internal_field_count, Object) |
| 6910 | |
| 6911 | static inline ObjectTemplateInfo* cast(Object* obj); |
| 6912 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6913 | #ifdef OBJECT_PRINT |
| 6914 | inline void ObjectTemplateInfoPrint() { |
| 6915 | ObjectTemplateInfoPrint(stdout); |
| 6916 | } |
| 6917 | void ObjectTemplateInfoPrint(FILE* out); |
| 6918 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6919 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6920 | void ObjectTemplateInfoVerify(); |
| 6921 | #endif |
| 6922 | |
| 6923 | static const int kConstructorOffset = TemplateInfo::kHeaderSize; |
| 6924 | static const int kInternalFieldCountOffset = |
| 6925 | kConstructorOffset + kPointerSize; |
| 6926 | static const int kSize = kInternalFieldCountOffset + kPointerSize; |
| 6927 | }; |
| 6928 | |
| 6929 | |
| 6930 | class SignatureInfo: public Struct { |
| 6931 | public: |
| 6932 | DECL_ACCESSORS(receiver, Object) |
| 6933 | DECL_ACCESSORS(args, Object) |
| 6934 | |
| 6935 | static inline SignatureInfo* cast(Object* obj); |
| 6936 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6937 | #ifdef OBJECT_PRINT |
| 6938 | inline void SignatureInfoPrint() { |
| 6939 | SignatureInfoPrint(stdout); |
| 6940 | } |
| 6941 | void SignatureInfoPrint(FILE* out); |
| 6942 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6943 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6944 | void SignatureInfoVerify(); |
| 6945 | #endif |
| 6946 | |
| 6947 | static const int kReceiverOffset = Struct::kHeaderSize; |
| 6948 | static const int kArgsOffset = kReceiverOffset + kPointerSize; |
| 6949 | static const int kSize = kArgsOffset + kPointerSize; |
| 6950 | |
| 6951 | private: |
| 6952 | DISALLOW_IMPLICIT_CONSTRUCTORS(SignatureInfo); |
| 6953 | }; |
| 6954 | |
| 6955 | |
| 6956 | class TypeSwitchInfo: public Struct { |
| 6957 | public: |
| 6958 | DECL_ACCESSORS(types, Object) |
| 6959 | |
| 6960 | static inline TypeSwitchInfo* cast(Object* obj); |
| 6961 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6962 | #ifdef OBJECT_PRINT |
| 6963 | inline void TypeSwitchInfoPrint() { |
| 6964 | TypeSwitchInfoPrint(stdout); |
| 6965 | } |
| 6966 | void TypeSwitchInfoPrint(FILE* out); |
| 6967 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6968 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6969 | void TypeSwitchInfoVerify(); |
| 6970 | #endif |
| 6971 | |
| 6972 | static const int kTypesOffset = Struct::kHeaderSize; |
| 6973 | static const int kSize = kTypesOffset + kPointerSize; |
| 6974 | }; |
| 6975 | |
| 6976 | |
| 6977 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 6978 | // The DebugInfo class holds additional information for a function being |
| 6979 | // debugged. |
| 6980 | class DebugInfo: public Struct { |
| 6981 | public: |
| 6982 | // The shared function info for the source being debugged. |
| 6983 | DECL_ACCESSORS(shared, SharedFunctionInfo) |
| 6984 | // Code object for the original code. |
| 6985 | DECL_ACCESSORS(original_code, Code) |
| 6986 | // Code object for the patched code. This code object is the code object |
| 6987 | // currently active for the function. |
| 6988 | DECL_ACCESSORS(code, Code) |
| 6989 | // Fixed array holding status information for each active break point. |
| 6990 | DECL_ACCESSORS(break_points, FixedArray) |
| 6991 | |
| 6992 | // Check if there is a break point at a code position. |
| 6993 | bool HasBreakPoint(int code_position); |
| 6994 | // Get the break point info object for a code position. |
| 6995 | Object* GetBreakPointInfo(int code_position); |
| 6996 | // Clear a break point. |
| 6997 | static void ClearBreakPoint(Handle<DebugInfo> debug_info, |
| 6998 | int code_position, |
| 6999 | Handle<Object> break_point_object); |
| 7000 | // Set a break point. |
| 7001 | static void SetBreakPoint(Handle<DebugInfo> debug_info, int code_position, |
| 7002 | int source_position, int statement_position, |
| 7003 | Handle<Object> break_point_object); |
| 7004 | // Get the break point objects for a code position. |
| 7005 | Object* GetBreakPointObjects(int code_position); |
| 7006 | // Find the break point info holding this break point object. |
| 7007 | static Object* FindBreakPointInfo(Handle<DebugInfo> debug_info, |
| 7008 | Handle<Object> break_point_object); |
| 7009 | // Get the number of break points for this function. |
| 7010 | int GetBreakPointCount(); |
| 7011 | |
| 7012 | static inline DebugInfo* cast(Object* obj); |
| 7013 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7014 | #ifdef OBJECT_PRINT |
| 7015 | inline void DebugInfoPrint() { |
| 7016 | DebugInfoPrint(stdout); |
| 7017 | } |
| 7018 | void DebugInfoPrint(FILE* out); |
| 7019 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7020 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7021 | void DebugInfoVerify(); |
| 7022 | #endif |
| 7023 | |
| 7024 | static const int kSharedFunctionInfoIndex = Struct::kHeaderSize; |
| 7025 | static const int kOriginalCodeIndex = kSharedFunctionInfoIndex + kPointerSize; |
| 7026 | static const int kPatchedCodeIndex = kOriginalCodeIndex + kPointerSize; |
| 7027 | static const int kActiveBreakPointsCountIndex = |
| 7028 | kPatchedCodeIndex + kPointerSize; |
| 7029 | static const int kBreakPointsStateIndex = |
| 7030 | kActiveBreakPointsCountIndex + kPointerSize; |
| 7031 | static const int kSize = kBreakPointsStateIndex + kPointerSize; |
| 7032 | |
| 7033 | private: |
| 7034 | static const int kNoBreakPointInfo = -1; |
| 7035 | |
| 7036 | // Lookup the index in the break_points array for a code position. |
| 7037 | int GetBreakPointInfoIndex(int code_position); |
| 7038 | |
| 7039 | DISALLOW_IMPLICIT_CONSTRUCTORS(DebugInfo); |
| 7040 | }; |
| 7041 | |
| 7042 | |
| 7043 | // The BreakPointInfo class holds information for break points set in a |
| 7044 | // function. The DebugInfo object holds a BreakPointInfo object for each code |
| 7045 | // position with one or more break points. |
| 7046 | class BreakPointInfo: public Struct { |
| 7047 | public: |
| 7048 | // The position in the code for the break point. |
| 7049 | DECL_ACCESSORS(code_position, Smi) |
| 7050 | // The position in the source for the break position. |
| 7051 | DECL_ACCESSORS(source_position, Smi) |
| 7052 | // The position in the source for the last statement before this break |
| 7053 | // position. |
| 7054 | DECL_ACCESSORS(statement_position, Smi) |
| 7055 | // List of related JavaScript break points. |
| 7056 | DECL_ACCESSORS(break_point_objects, Object) |
| 7057 | |
| 7058 | // Removes a break point. |
| 7059 | static void ClearBreakPoint(Handle<BreakPointInfo> info, |
| 7060 | Handle<Object> break_point_object); |
| 7061 | // Set a break point. |
| 7062 | static void SetBreakPoint(Handle<BreakPointInfo> info, |
| 7063 | Handle<Object> break_point_object); |
| 7064 | // Check if break point info has this break point object. |
| 7065 | static bool HasBreakPointObject(Handle<BreakPointInfo> info, |
| 7066 | Handle<Object> break_point_object); |
| 7067 | // Get the number of break points for this code position. |
| 7068 | int GetBreakPointCount(); |
| 7069 | |
| 7070 | static inline BreakPointInfo* cast(Object* obj); |
| 7071 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7072 | #ifdef OBJECT_PRINT |
| 7073 | inline void BreakPointInfoPrint() { |
| 7074 | BreakPointInfoPrint(stdout); |
| 7075 | } |
| 7076 | void BreakPointInfoPrint(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 BreakPointInfoVerify(); |
| 7080 | #endif |
| 7081 | |
| 7082 | static const int kCodePositionIndex = Struct::kHeaderSize; |
| 7083 | static const int kSourcePositionIndex = kCodePositionIndex + kPointerSize; |
| 7084 | static const int kStatementPositionIndex = |
| 7085 | kSourcePositionIndex + kPointerSize; |
| 7086 | static const int kBreakPointObjectsIndex = |
| 7087 | kStatementPositionIndex + kPointerSize; |
| 7088 | static const int kSize = kBreakPointObjectsIndex + kPointerSize; |
| 7089 | |
| 7090 | private: |
| 7091 | DISALLOW_IMPLICIT_CONSTRUCTORS(BreakPointInfo); |
| 7092 | }; |
| 7093 | #endif // ENABLE_DEBUGGER_SUPPORT |
| 7094 | |
| 7095 | |
| 7096 | #undef DECL_BOOLEAN_ACCESSORS |
| 7097 | #undef DECL_ACCESSORS |
| 7098 | |
| 7099 | |
| 7100 | // Abstract base class for visiting, and optionally modifying, the |
| 7101 | // pointers contained in Objects. Used in GC and serialization/deserialization. |
| 7102 | class ObjectVisitor BASE_EMBEDDED { |
| 7103 | public: |
| 7104 | virtual ~ObjectVisitor() {} |
| 7105 | |
| 7106 | // Visits a contiguous arrays of pointers in the half-open range |
| 7107 | // [start, end). Any or all of the values may be modified on return. |
| 7108 | virtual void VisitPointers(Object** start, Object** end) = 0; |
| 7109 | |
| 7110 | // To allow lazy clearing of inline caches the visitor has |
| 7111 | // a rich interface for iterating over Code objects.. |
| 7112 | |
| 7113 | // Visits a code target in the instruction stream. |
| 7114 | virtual void VisitCodeTarget(RelocInfo* rinfo); |
| 7115 | |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 7116 | // Visits a code entry in a JS function. |
| 7117 | virtual void VisitCodeEntry(Address entry_address); |
| 7118 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 7119 | // Visits a global property cell reference in the instruction stream. |
| 7120 | virtual void VisitGlobalPropertyCell(RelocInfo* rinfo); |
| 7121 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7122 | // Visits a runtime entry in the instruction stream. |
| 7123 | virtual void VisitRuntimeEntry(RelocInfo* rinfo) {} |
| 7124 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 7125 | // Visits the resource of an ASCII or two-byte string. |
| 7126 | virtual void VisitExternalAsciiString( |
| 7127 | v8::String::ExternalAsciiStringResource** resource) {} |
| 7128 | virtual void VisitExternalTwoByteString( |
| 7129 | v8::String::ExternalStringResource** resource) {} |
| 7130 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7131 | // Visits a debug call target in the instruction stream. |
| 7132 | virtual void VisitDebugTarget(RelocInfo* rinfo); |
| 7133 | |
| 7134 | // Handy shorthand for visiting a single pointer. |
| 7135 | virtual void VisitPointer(Object** p) { VisitPointers(p, p + 1); } |
| 7136 | |
| 7137 | // Visits a contiguous arrays of external references (references to the C++ |
| 7138 | // heap) in the half-open range [start, end). Any or all of the values |
| 7139 | // may be modified on return. |
| 7140 | virtual void VisitExternalReferences(Address* start, Address* end) {} |
| 7141 | |
| 7142 | inline void VisitExternalReference(Address* p) { |
| 7143 | VisitExternalReferences(p, p + 1); |
| 7144 | } |
| 7145 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 7146 | // Visits a handle that has an embedder-assigned class ID. |
| 7147 | virtual void VisitEmbedderReference(Object** p, uint16_t class_id) {} |
| 7148 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7149 | #ifdef DEBUG |
| 7150 | // Intended for serialization/deserialization checking: insert, or |
| 7151 | // check for the presence of, a tag at this position in the stream. |
| 7152 | virtual void Synchronize(const char* tag) {} |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 7153 | #else |
| 7154 | inline void Synchronize(const char* tag) {} |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7155 | #endif |
| 7156 | }; |
| 7157 | |
| 7158 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 7159 | class StructBodyDescriptor : public |
| 7160 | FlexibleBodyDescriptor<HeapObject::kHeaderSize> { |
| 7161 | public: |
| 7162 | static inline int SizeOf(Map* map, HeapObject* object) { |
| 7163 | return map->instance_size(); |
| 7164 | } |
| 7165 | }; |
| 7166 | |
| 7167 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 7168 | // BooleanBit is a helper class for setting and getting a bit in an |
| 7169 | // integer or Smi. |
| 7170 | class BooleanBit : public AllStatic { |
| 7171 | public: |
| 7172 | static inline bool get(Smi* smi, int bit_position) { |
| 7173 | return get(smi->value(), bit_position); |
| 7174 | } |
| 7175 | |
| 7176 | static inline bool get(int value, int bit_position) { |
| 7177 | return (value & (1 << bit_position)) != 0; |
| 7178 | } |
| 7179 | |
| 7180 | static inline Smi* set(Smi* smi, int bit_position, bool v) { |
| 7181 | return Smi::FromInt(set(smi->value(), bit_position, v)); |
| 7182 | } |
| 7183 | |
| 7184 | static inline int set(int value, int bit_position, bool v) { |
| 7185 | if (v) { |
| 7186 | value |= (1 << bit_position); |
| 7187 | } else { |
| 7188 | value &= ~(1 << bit_position); |
| 7189 | } |
| 7190 | return value; |
| 7191 | } |
| 7192 | }; |
| 7193 | |
| 7194 | } } // namespace v8::internal |
| 7195 | |
| 7196 | #endif // V8_OBJECTS_H_ |