Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 1 | // Copyright 2010 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 | |
| 31 | #include "builtins.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 32 | #include "smart-pointer.h" |
| 33 | #include "unicode-inl.h" |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 34 | #if V8_TARGET_ARCH_ARM |
| 35 | #include "arm/constants-arm.h" |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 36 | #elif V8_TARGET_ARCH_MIPS |
| 37 | #include "mips/constants-mips.h" |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 38 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 39 | |
| 40 | // |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 41 | // Most object types in the V8 JavaScript are described in this file. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 42 | // |
| 43 | // Inheritance hierarchy: |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 44 | // - MaybeObject (an object or a failure) |
| 45 | // - Failure (immediate for marking failed operation) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 46 | // - Object |
| 47 | // - Smi (immediate small integer) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 48 | // - HeapObject (superclass for everything allocated in the heap) |
| 49 | // - JSObject |
| 50 | // - JSArray |
| 51 | // - JSRegExp |
| 52 | // - JSFunction |
| 53 | // - GlobalObject |
| 54 | // - JSGlobalObject |
| 55 | // - JSBuiltinsObject |
| 56 | // - JSGlobalProxy |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 57 | // - JSValue |
| 58 | // - JSMessageObject |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 59 | // - ByteArray |
| 60 | // - PixelArray |
| 61 | // - ExternalArray |
| 62 | // - ExternalByteArray |
| 63 | // - ExternalUnsignedByteArray |
| 64 | // - ExternalShortArray |
| 65 | // - ExternalUnsignedShortArray |
| 66 | // - ExternalIntArray |
| 67 | // - ExternalUnsignedIntArray |
| 68 | // - ExternalFloatArray |
| 69 | // - FixedArray |
| 70 | // - DescriptorArray |
| 71 | // - HashTable |
| 72 | // - Dictionary |
| 73 | // - SymbolTable |
| 74 | // - CompilationCacheTable |
| 75 | // - CodeCacheHashTable |
| 76 | // - MapCache |
| 77 | // - Context |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 78 | // - JSFunctionResultCache |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 79 | // - SerializedScopeInfo |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 80 | // - String |
| 81 | // - SeqString |
| 82 | // - SeqAsciiString |
| 83 | // - SeqTwoByteString |
| 84 | // - ConsString |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 85 | // - ExternalString |
| 86 | // - ExternalAsciiString |
| 87 | // - ExternalTwoByteString |
| 88 | // - HeapNumber |
| 89 | // - Code |
| 90 | // - Map |
| 91 | // - Oddball |
| 92 | // - Proxy |
| 93 | // - SharedFunctionInfo |
| 94 | // - Struct |
| 95 | // - AccessorInfo |
| 96 | // - AccessCheckInfo |
| 97 | // - InterceptorInfo |
| 98 | // - CallHandlerInfo |
| 99 | // - TemplateInfo |
| 100 | // - FunctionTemplateInfo |
| 101 | // - ObjectTemplateInfo |
| 102 | // - Script |
| 103 | // - SignatureInfo |
| 104 | // - TypeSwitchInfo |
| 105 | // - DebugInfo |
| 106 | // - BreakPointInfo |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 107 | // - CodeCache |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 108 | // |
| 109 | // Formats of Object*: |
| 110 | // Smi: [31 bit signed int] 0 |
| 111 | // HeapObject: [32 bit direct pointer] (4 byte aligned) | 01 |
| 112 | // Failure: [30 bit signed int] 11 |
| 113 | |
| 114 | // Ecma-262 3rd 8.6.1 |
| 115 | enum PropertyAttributes { |
| 116 | NONE = v8::None, |
| 117 | READ_ONLY = v8::ReadOnly, |
| 118 | DONT_ENUM = v8::DontEnum, |
| 119 | DONT_DELETE = v8::DontDelete, |
| 120 | ABSENT = 16 // Used in runtime to indicate a property is absent. |
| 121 | // ABSENT can never be stored in or returned from a descriptor's attributes |
| 122 | // bitfield. It is only used as a return value meaning the attributes of |
| 123 | // a non-existent property. |
| 124 | }; |
| 125 | |
| 126 | namespace v8 { |
| 127 | namespace internal { |
| 128 | |
| 129 | |
| 130 | // PropertyDetails captures type and attributes for a property. |
| 131 | // They are used both in property dictionaries and instance descriptors. |
| 132 | class PropertyDetails BASE_EMBEDDED { |
| 133 | public: |
| 134 | |
| 135 | PropertyDetails(PropertyAttributes attributes, |
| 136 | PropertyType type, |
| 137 | int index = 0) { |
| 138 | ASSERT(TypeField::is_valid(type)); |
| 139 | ASSERT(AttributesField::is_valid(attributes)); |
| 140 | ASSERT(IndexField::is_valid(index)); |
| 141 | |
| 142 | value_ = TypeField::encode(type) |
| 143 | | AttributesField::encode(attributes) |
| 144 | | IndexField::encode(index); |
| 145 | |
| 146 | ASSERT(type == this->type()); |
| 147 | ASSERT(attributes == this->attributes()); |
| 148 | ASSERT(index == this->index()); |
| 149 | } |
| 150 | |
| 151 | // Conversion for storing details as Object*. |
| 152 | inline PropertyDetails(Smi* smi); |
| 153 | inline Smi* AsSmi(); |
| 154 | |
| 155 | PropertyType type() { return TypeField::decode(value_); } |
| 156 | |
| 157 | bool IsTransition() { |
| 158 | PropertyType t = type(); |
| 159 | ASSERT(t != INTERCEPTOR); |
| 160 | return t == MAP_TRANSITION || t == CONSTANT_TRANSITION; |
| 161 | } |
| 162 | |
| 163 | bool IsProperty() { |
| 164 | return type() < FIRST_PHANTOM_PROPERTY_TYPE; |
| 165 | } |
| 166 | |
| 167 | PropertyAttributes attributes() { return AttributesField::decode(value_); } |
| 168 | |
| 169 | int index() { return IndexField::decode(value_); } |
| 170 | |
| 171 | inline PropertyDetails AsDeleted(); |
| 172 | |
| 173 | static bool IsValidIndex(int index) { return IndexField::is_valid(index); } |
| 174 | |
| 175 | bool IsReadOnly() { return (attributes() & READ_ONLY) != 0; } |
| 176 | bool IsDontDelete() { return (attributes() & DONT_DELETE) != 0; } |
| 177 | bool IsDontEnum() { return (attributes() & DONT_ENUM) != 0; } |
| 178 | bool IsDeleted() { return DeletedField::decode(value_) != 0;} |
| 179 | |
| 180 | // Bit fields in value_ (type, shift, size). Must be public so the |
| 181 | // constants can be embedded in generated code. |
| 182 | class TypeField: public BitField<PropertyType, 0, 3> {}; |
| 183 | class AttributesField: public BitField<PropertyAttributes, 3, 3> {}; |
| 184 | class DeletedField: public BitField<uint32_t, 6, 1> {}; |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 185 | class IndexField: public BitField<uint32_t, 7, 32-7> {}; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 186 | |
| 187 | static const int kInitialIndex = 1; |
| 188 | private: |
| 189 | uint32_t value_; |
| 190 | }; |
| 191 | |
| 192 | |
| 193 | // Setter that skips the write barrier if mode is SKIP_WRITE_BARRIER. |
| 194 | enum WriteBarrierMode { SKIP_WRITE_BARRIER, UPDATE_WRITE_BARRIER }; |
| 195 | |
| 196 | |
| 197 | // PropertyNormalizationMode is used to specify whether to keep |
| 198 | // inobject properties when normalizing properties of a JSObject. |
| 199 | enum PropertyNormalizationMode { |
| 200 | CLEAR_INOBJECT_PROPERTIES, |
| 201 | KEEP_INOBJECT_PROPERTIES |
| 202 | }; |
| 203 | |
| 204 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 205 | // NormalizedMapSharingMode is used to specify whether a map may be shared |
| 206 | // by different objects with normalized properties. |
| 207 | enum NormalizedMapSharingMode { |
| 208 | UNIQUE_NORMALIZED_MAP, |
| 209 | SHARED_NORMALIZED_MAP |
| 210 | }; |
| 211 | |
| 212 | |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 213 | // Instance size sentinel for objects of variable size. |
| 214 | static const int kVariableSizeSentinel = 0; |
| 215 | |
| 216 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 217 | // All Maps have a field instance_type containing a InstanceType. |
| 218 | // It describes the type of the instances. |
| 219 | // |
| 220 | // As an example, a JavaScript object is a heap object and its map |
| 221 | // instance_type is JS_OBJECT_TYPE. |
| 222 | // |
| 223 | // The names of the string instance types are intended to systematically |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 224 | // mirror their encoding in the instance_type field of the map. The default |
| 225 | // encoding is considered TWO_BYTE. It is not mentioned in the name. ASCII |
| 226 | // encoding is mentioned explicitly in the name. Likewise, the default |
| 227 | // representation is considered sequential. It is not mentioned in the |
| 228 | // name. The other representations (eg, CONS, EXTERNAL) are explicitly |
| 229 | // mentioned. Finally, the string is either a SYMBOL_TYPE (if it is a |
| 230 | // symbol) or a STRING_TYPE (if it is not a symbol). |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 231 | // |
| 232 | // NOTE: The following things are some that depend on the string types having |
| 233 | // instance_types that are less than those of all other types: |
| 234 | // HeapObject::Size, HeapObject::IterateBody, the typeof operator, and |
| 235 | // Object::IsString. |
| 236 | // |
| 237 | // NOTE: Everything following JS_VALUE_TYPE is considered a |
| 238 | // JSObject for GC purposes. The first four entries here have typeof |
| 239 | // 'object', whereas JS_FUNCTION_TYPE has typeof 'function'. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 240 | #define INSTANCE_TYPE_LIST_ALL(V) \ |
| 241 | V(SYMBOL_TYPE) \ |
| 242 | V(ASCII_SYMBOL_TYPE) \ |
| 243 | V(CONS_SYMBOL_TYPE) \ |
| 244 | V(CONS_ASCII_SYMBOL_TYPE) \ |
| 245 | V(EXTERNAL_SYMBOL_TYPE) \ |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 246 | V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 247 | V(EXTERNAL_ASCII_SYMBOL_TYPE) \ |
| 248 | V(STRING_TYPE) \ |
| 249 | V(ASCII_STRING_TYPE) \ |
| 250 | V(CONS_STRING_TYPE) \ |
| 251 | V(CONS_ASCII_STRING_TYPE) \ |
| 252 | V(EXTERNAL_STRING_TYPE) \ |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 253 | V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 254 | V(EXTERNAL_ASCII_STRING_TYPE) \ |
| 255 | V(PRIVATE_EXTERNAL_ASCII_STRING_TYPE) \ |
| 256 | \ |
| 257 | V(MAP_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 258 | V(CODE_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 259 | V(ODDBALL_TYPE) \ |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 260 | V(JS_GLOBAL_PROPERTY_CELL_TYPE) \ |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 261 | \ |
| 262 | V(HEAP_NUMBER_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 263 | V(PROXY_TYPE) \ |
| 264 | V(BYTE_ARRAY_TYPE) \ |
| 265 | V(PIXEL_ARRAY_TYPE) \ |
| 266 | /* Note: the order of these external array */ \ |
| 267 | /* types is relied upon in */ \ |
| 268 | /* Object::IsExternalArray(). */ \ |
| 269 | V(EXTERNAL_BYTE_ARRAY_TYPE) \ |
| 270 | V(EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE) \ |
| 271 | V(EXTERNAL_SHORT_ARRAY_TYPE) \ |
| 272 | V(EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE) \ |
| 273 | V(EXTERNAL_INT_ARRAY_TYPE) \ |
| 274 | V(EXTERNAL_UNSIGNED_INT_ARRAY_TYPE) \ |
| 275 | V(EXTERNAL_FLOAT_ARRAY_TYPE) \ |
| 276 | V(FILLER_TYPE) \ |
| 277 | \ |
| 278 | V(ACCESSOR_INFO_TYPE) \ |
| 279 | V(ACCESS_CHECK_INFO_TYPE) \ |
| 280 | V(INTERCEPTOR_INFO_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 281 | V(CALL_HANDLER_INFO_TYPE) \ |
| 282 | V(FUNCTION_TEMPLATE_INFO_TYPE) \ |
| 283 | V(OBJECT_TEMPLATE_INFO_TYPE) \ |
| 284 | V(SIGNATURE_INFO_TYPE) \ |
| 285 | V(TYPE_SWITCH_INFO_TYPE) \ |
| 286 | V(SCRIPT_TYPE) \ |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 287 | V(CODE_CACHE_TYPE) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 288 | \ |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 289 | V(FIXED_ARRAY_TYPE) \ |
| 290 | V(SHARED_FUNCTION_INFO_TYPE) \ |
| 291 | \ |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 292 | V(JS_MESSAGE_OBJECT_TYPE) \ |
| 293 | \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 294 | V(JS_VALUE_TYPE) \ |
| 295 | V(JS_OBJECT_TYPE) \ |
| 296 | V(JS_CONTEXT_EXTENSION_OBJECT_TYPE) \ |
| 297 | V(JS_GLOBAL_OBJECT_TYPE) \ |
| 298 | V(JS_BUILTINS_OBJECT_TYPE) \ |
| 299 | V(JS_GLOBAL_PROXY_TYPE) \ |
| 300 | V(JS_ARRAY_TYPE) \ |
| 301 | V(JS_REGEXP_TYPE) \ |
| 302 | \ |
| 303 | V(JS_FUNCTION_TYPE) \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 304 | |
| 305 | #ifdef ENABLE_DEBUGGER_SUPPORT |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 306 | #define INSTANCE_TYPE_LIST_DEBUGGER(V) \ |
| 307 | V(DEBUG_INFO_TYPE) \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 308 | V(BREAK_POINT_INFO_TYPE) |
| 309 | #else |
| 310 | #define INSTANCE_TYPE_LIST_DEBUGGER(V) |
| 311 | #endif |
| 312 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 313 | #define INSTANCE_TYPE_LIST(V) \ |
| 314 | INSTANCE_TYPE_LIST_ALL(V) \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 315 | INSTANCE_TYPE_LIST_DEBUGGER(V) |
| 316 | |
| 317 | |
| 318 | // Since string types are not consecutive, this macro is used to |
| 319 | // iterate over them. |
| 320 | #define STRING_TYPE_LIST(V) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 321 | V(SYMBOL_TYPE, \ |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 322 | kVariableSizeSentinel, \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 323 | symbol, \ |
| 324 | Symbol) \ |
| 325 | V(ASCII_SYMBOL_TYPE, \ |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 326 | kVariableSizeSentinel, \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 327 | ascii_symbol, \ |
| 328 | AsciiSymbol) \ |
| 329 | V(CONS_SYMBOL_TYPE, \ |
| 330 | ConsString::kSize, \ |
| 331 | cons_symbol, \ |
| 332 | ConsSymbol) \ |
| 333 | V(CONS_ASCII_SYMBOL_TYPE, \ |
| 334 | ConsString::kSize, \ |
| 335 | cons_ascii_symbol, \ |
| 336 | ConsAsciiSymbol) \ |
| 337 | V(EXTERNAL_SYMBOL_TYPE, \ |
| 338 | ExternalTwoByteString::kSize, \ |
| 339 | external_symbol, \ |
| 340 | ExternalSymbol) \ |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 341 | V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE, \ |
| 342 | ExternalTwoByteString::kSize, \ |
| 343 | external_symbol_with_ascii_data, \ |
| 344 | ExternalSymbolWithAsciiData) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 345 | V(EXTERNAL_ASCII_SYMBOL_TYPE, \ |
| 346 | ExternalAsciiString::kSize, \ |
| 347 | external_ascii_symbol, \ |
| 348 | ExternalAsciiSymbol) \ |
| 349 | V(STRING_TYPE, \ |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 350 | kVariableSizeSentinel, \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 351 | string, \ |
| 352 | String) \ |
| 353 | V(ASCII_STRING_TYPE, \ |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 354 | kVariableSizeSentinel, \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 355 | ascii_string, \ |
| 356 | AsciiString) \ |
| 357 | V(CONS_STRING_TYPE, \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 358 | ConsString::kSize, \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 359 | cons_string, \ |
| 360 | ConsString) \ |
| 361 | V(CONS_ASCII_STRING_TYPE, \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 362 | ConsString::kSize, \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 363 | cons_ascii_string, \ |
| 364 | ConsAsciiString) \ |
| 365 | V(EXTERNAL_STRING_TYPE, \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 366 | ExternalTwoByteString::kSize, \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 367 | external_string, \ |
| 368 | ExternalString) \ |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 369 | V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE, \ |
| 370 | ExternalTwoByteString::kSize, \ |
| 371 | external_string_with_ascii_data, \ |
| 372 | ExternalStringWithAsciiData) \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 373 | V(EXTERNAL_ASCII_STRING_TYPE, \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 374 | ExternalAsciiString::kSize, \ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 375 | external_ascii_string, \ |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 376 | ExternalAsciiString) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 377 | |
| 378 | // A struct is a simple object a set of object-valued fields. Including an |
| 379 | // object type in this causes the compiler to generate most of the boilerplate |
| 380 | // code for the class including allocation and garbage collection routines, |
| 381 | // casts and predicates. All you need to define is the class, methods and |
| 382 | // object verification routines. Easy, no? |
| 383 | // |
| 384 | // Note that for subtle reasons related to the ordering or numerical values of |
| 385 | // type tags, elements in this list have to be added to the INSTANCE_TYPE_LIST |
| 386 | // manually. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 387 | #define STRUCT_LIST_ALL(V) \ |
| 388 | V(ACCESSOR_INFO, AccessorInfo, accessor_info) \ |
| 389 | V(ACCESS_CHECK_INFO, AccessCheckInfo, access_check_info) \ |
| 390 | V(INTERCEPTOR_INFO, InterceptorInfo, interceptor_info) \ |
| 391 | V(CALL_HANDLER_INFO, CallHandlerInfo, call_handler_info) \ |
| 392 | V(FUNCTION_TEMPLATE_INFO, FunctionTemplateInfo, function_template_info) \ |
| 393 | V(OBJECT_TEMPLATE_INFO, ObjectTemplateInfo, object_template_info) \ |
| 394 | V(SIGNATURE_INFO, SignatureInfo, signature_info) \ |
| 395 | V(TYPE_SWITCH_INFO, TypeSwitchInfo, type_switch_info) \ |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 396 | V(SCRIPT, Script, script) \ |
| 397 | V(CODE_CACHE, CodeCache, code_cache) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 398 | |
| 399 | #ifdef ENABLE_DEBUGGER_SUPPORT |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 400 | #define STRUCT_LIST_DEBUGGER(V) \ |
| 401 | V(DEBUG_INFO, DebugInfo, debug_info) \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 402 | V(BREAK_POINT_INFO, BreakPointInfo, break_point_info) |
| 403 | #else |
| 404 | #define STRUCT_LIST_DEBUGGER(V) |
| 405 | #endif |
| 406 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 407 | #define STRUCT_LIST(V) \ |
| 408 | STRUCT_LIST_ALL(V) \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 409 | STRUCT_LIST_DEBUGGER(V) |
| 410 | |
| 411 | // We use the full 8 bits of the instance_type field to encode heap object |
| 412 | // instance types. The high-order bit (bit 7) is set if the object is not a |
| 413 | // string, and cleared if it is a string. |
| 414 | const uint32_t kIsNotStringMask = 0x80; |
| 415 | const uint32_t kStringTag = 0x0; |
| 416 | const uint32_t kNotStringTag = 0x80; |
| 417 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 418 | // Bit 6 indicates that the object is a symbol (if set) or not (if cleared). |
| 419 | // There are not enough types that the non-string types (with bit 7 set) can |
| 420 | // have bit 6 set too. |
| 421 | const uint32_t kIsSymbolMask = 0x40; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 422 | const uint32_t kNotSymbolTag = 0x0; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 423 | const uint32_t kSymbolTag = 0x40; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 424 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 425 | // If bit 7 is clear then bit 2 indicates whether the string consists of |
| 426 | // two-byte characters or one-byte characters. |
| 427 | const uint32_t kStringEncodingMask = 0x4; |
| 428 | const uint32_t kTwoByteStringTag = 0x0; |
| 429 | const uint32_t kAsciiStringTag = 0x4; |
| 430 | |
| 431 | // If bit 7 is clear, the low-order 2 bits indicate the representation |
| 432 | // of the string. |
| 433 | const uint32_t kStringRepresentationMask = 0x03; |
| 434 | enum StringRepresentationTag { |
| 435 | kSeqStringTag = 0x0, |
| 436 | kConsStringTag = 0x1, |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 437 | kExternalStringTag = 0x2 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 438 | }; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 439 | const uint32_t kIsConsStringMask = 0x1; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 440 | |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 441 | // If bit 7 is clear, then bit 3 indicates whether this two-byte |
| 442 | // string actually contains ascii data. |
| 443 | const uint32_t kAsciiDataHintMask = 0x08; |
| 444 | const uint32_t kAsciiDataHintTag = 0x08; |
| 445 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 446 | |
| 447 | // A ConsString with an empty string as the right side is a candidate |
| 448 | // for being shortcut by the garbage collector unless it is a |
| 449 | // symbol. It's not common to have non-flat symbols, so we do not |
| 450 | // shortcut them thereby avoiding turning symbols into strings. See |
| 451 | // heap.cc and mark-compact.cc. |
| 452 | const uint32_t kShortcutTypeMask = |
| 453 | kIsNotStringMask | |
| 454 | kIsSymbolMask | |
| 455 | kStringRepresentationMask; |
| 456 | const uint32_t kShortcutTypeTag = kConsStringTag; |
| 457 | |
| 458 | |
| 459 | enum InstanceType { |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 460 | // String types. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 461 | // FIRST_STRING_TYPE |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 462 | SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kSeqStringTag, |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 463 | ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kSeqStringTag, |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 464 | CONS_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kConsStringTag, |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 465 | CONS_ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kConsStringTag, |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 466 | EXTERNAL_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kExternalStringTag, |
| 467 | EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE = |
| 468 | kTwoByteStringTag | kSymbolTag | kExternalStringTag | kAsciiDataHintTag, |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 469 | EXTERNAL_ASCII_SYMBOL_TYPE = |
| 470 | kAsciiStringTag | kSymbolTag | kExternalStringTag, |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 471 | STRING_TYPE = kTwoByteStringTag | kSeqStringTag, |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 472 | ASCII_STRING_TYPE = kAsciiStringTag | kSeqStringTag, |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 473 | CONS_STRING_TYPE = kTwoByteStringTag | kConsStringTag, |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 474 | CONS_ASCII_STRING_TYPE = kAsciiStringTag | kConsStringTag, |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 475 | EXTERNAL_STRING_TYPE = kTwoByteStringTag | kExternalStringTag, |
| 476 | EXTERNAL_STRING_WITH_ASCII_DATA_TYPE = |
| 477 | kTwoByteStringTag | kExternalStringTag | kAsciiDataHintTag, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 478 | // LAST_STRING_TYPE |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 479 | EXTERNAL_ASCII_STRING_TYPE = kAsciiStringTag | kExternalStringTag, |
| 480 | PRIVATE_EXTERNAL_ASCII_STRING_TYPE = EXTERNAL_ASCII_STRING_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 481 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 482 | // Objects allocated in their own spaces (never in new space). |
| 483 | MAP_TYPE = kNotStringTag, // FIRST_NONSTRING_TYPE |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 484 | CODE_TYPE, |
| 485 | ODDBALL_TYPE, |
| 486 | JS_GLOBAL_PROPERTY_CELL_TYPE, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 487 | |
| 488 | // "Data", objects that cannot contain non-map-word pointers to heap |
| 489 | // objects. |
| 490 | HEAP_NUMBER_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 491 | PROXY_TYPE, |
| 492 | BYTE_ARRAY_TYPE, |
| 493 | PIXEL_ARRAY_TYPE, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 494 | EXTERNAL_BYTE_ARRAY_TYPE, // FIRST_EXTERNAL_ARRAY_TYPE |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 495 | EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE, |
| 496 | EXTERNAL_SHORT_ARRAY_TYPE, |
| 497 | EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE, |
| 498 | EXTERNAL_INT_ARRAY_TYPE, |
| 499 | EXTERNAL_UNSIGNED_INT_ARRAY_TYPE, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 500 | EXTERNAL_FLOAT_ARRAY_TYPE, // LAST_EXTERNAL_ARRAY_TYPE |
| 501 | FILLER_TYPE, // LAST_DATA_TYPE |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 502 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 503 | // Structs. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 504 | ACCESSOR_INFO_TYPE, |
| 505 | ACCESS_CHECK_INFO_TYPE, |
| 506 | INTERCEPTOR_INFO_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 507 | CALL_HANDLER_INFO_TYPE, |
| 508 | FUNCTION_TEMPLATE_INFO_TYPE, |
| 509 | OBJECT_TEMPLATE_INFO_TYPE, |
| 510 | SIGNATURE_INFO_TYPE, |
| 511 | TYPE_SWITCH_INFO_TYPE, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 512 | SCRIPT_TYPE, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 513 | CODE_CACHE_TYPE, |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 514 | // The following two instance types are only used when ENABLE_DEBUGGER_SUPPORT |
| 515 | // is defined. However as include/v8.h contain some of the instance type |
| 516 | // constants always having them avoids them getting different numbers |
| 517 | // depending on whether ENABLE_DEBUGGER_SUPPORT is defined or not. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 518 | DEBUG_INFO_TYPE, |
| 519 | BREAK_POINT_INFO_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 520 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 521 | FIXED_ARRAY_TYPE, |
| 522 | SHARED_FUNCTION_INFO_TYPE, |
| 523 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 524 | JS_MESSAGE_OBJECT_TYPE, |
| 525 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 526 | JS_VALUE_TYPE, // FIRST_JS_OBJECT_TYPE |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 527 | JS_OBJECT_TYPE, |
| 528 | JS_CONTEXT_EXTENSION_OBJECT_TYPE, |
| 529 | JS_GLOBAL_OBJECT_TYPE, |
| 530 | JS_BUILTINS_OBJECT_TYPE, |
| 531 | JS_GLOBAL_PROXY_TYPE, |
| 532 | JS_ARRAY_TYPE, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 533 | |
| 534 | JS_REGEXP_TYPE, // LAST_JS_OBJECT_TYPE, FIRST_FUNCTION_CLASS_TYPE |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 535 | |
| 536 | JS_FUNCTION_TYPE, |
| 537 | |
| 538 | // Pseudo-types |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 539 | FIRST_TYPE = 0x0, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 540 | LAST_TYPE = JS_FUNCTION_TYPE, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 541 | INVALID_TYPE = FIRST_TYPE - 1, |
| 542 | FIRST_NONSTRING_TYPE = MAP_TYPE, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 543 | FIRST_STRING_TYPE = FIRST_TYPE, |
| 544 | LAST_STRING_TYPE = FIRST_NONSTRING_TYPE - 1, |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 545 | // Boundaries for testing for an external array. |
| 546 | FIRST_EXTERNAL_ARRAY_TYPE = EXTERNAL_BYTE_ARRAY_TYPE, |
| 547 | LAST_EXTERNAL_ARRAY_TYPE = EXTERNAL_FLOAT_ARRAY_TYPE, |
| 548 | // Boundary for promotion to old data space/old pointer space. |
| 549 | LAST_DATA_TYPE = FILLER_TYPE, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 550 | // Boundaries for testing the type is a JavaScript "object". Note that |
| 551 | // function objects are not counted as objects, even though they are |
| 552 | // implemented as such; only values whose typeof is "object" are included. |
| 553 | FIRST_JS_OBJECT_TYPE = JS_VALUE_TYPE, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 554 | LAST_JS_OBJECT_TYPE = JS_REGEXP_TYPE, |
| 555 | // RegExp objects have [[Class]] "function" because they are callable. |
| 556 | // All types from this type and above are objects with [[Class]] "function". |
| 557 | FIRST_FUNCTION_CLASS_TYPE = JS_REGEXP_TYPE |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 558 | }; |
| 559 | |
| 560 | |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 561 | STATIC_CHECK(JS_OBJECT_TYPE == Internals::kJSObjectType); |
| 562 | STATIC_CHECK(FIRST_NONSTRING_TYPE == Internals::kFirstNonstringType); |
| 563 | STATIC_CHECK(PROXY_TYPE == Internals::kProxyType); |
| 564 | |
| 565 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 566 | enum CompareResult { |
| 567 | LESS = -1, |
| 568 | EQUAL = 0, |
| 569 | GREATER = 1, |
| 570 | |
| 571 | NOT_EQUAL = GREATER |
| 572 | }; |
| 573 | |
| 574 | |
| 575 | #define DECL_BOOLEAN_ACCESSORS(name) \ |
| 576 | inline bool name(); \ |
| 577 | inline void set_##name(bool value); \ |
| 578 | |
| 579 | |
| 580 | #define DECL_ACCESSORS(name, type) \ |
| 581 | inline type* name(); \ |
| 582 | inline void set_##name(type* value, \ |
| 583 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); \ |
| 584 | |
| 585 | |
| 586 | class StringStream; |
| 587 | class ObjectVisitor; |
| 588 | |
| 589 | struct ValueInfo : public Malloced { |
| 590 | ValueInfo() : type(FIRST_TYPE), ptr(NULL), str(NULL), number(0) { } |
| 591 | InstanceType type; |
| 592 | Object* ptr; |
| 593 | const char* str; |
| 594 | double number; |
| 595 | }; |
| 596 | |
| 597 | |
| 598 | // A template-ized version of the IsXXX functions. |
| 599 | template <class C> static inline bool Is(Object* obj); |
| 600 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 601 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 602 | class MaybeObject BASE_EMBEDDED { |
| 603 | public: |
| 604 | inline bool IsFailure(); |
| 605 | inline bool IsRetryAfterGC(); |
| 606 | inline bool IsOutOfMemory(); |
| 607 | inline bool IsException(); |
| 608 | INLINE(bool IsTheHole()); |
| 609 | inline bool ToObject(Object** obj) { |
| 610 | if (IsFailure()) return false; |
| 611 | *obj = reinterpret_cast<Object*>(this); |
| 612 | return true; |
| 613 | } |
| 614 | inline Object* ToObjectUnchecked() { |
| 615 | ASSERT(!IsFailure()); |
| 616 | return reinterpret_cast<Object*>(this); |
| 617 | } |
| 618 | inline Object* ToObjectChecked() { |
| 619 | CHECK(!IsFailure()); |
| 620 | return reinterpret_cast<Object*>(this); |
| 621 | } |
| 622 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 623 | #ifdef OBJECT_PRINT |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 624 | // Prints this object with details. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 625 | inline void Print() { |
| 626 | Print(stdout); |
| 627 | }; |
| 628 | inline void PrintLn() { |
| 629 | PrintLn(stdout); |
| 630 | } |
| 631 | void Print(FILE* out); |
| 632 | void PrintLn(FILE* out); |
| 633 | #endif |
| 634 | #ifdef DEBUG |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 635 | // Verifies the object. |
| 636 | void Verify(); |
| 637 | #endif |
| 638 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 639 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 640 | |
| 641 | #define OBJECT_TYPE_LIST(V) \ |
| 642 | V(Smi) \ |
| 643 | V(HeapObject) \ |
| 644 | V(Number) \ |
| 645 | |
| 646 | #define HEAP_OBJECT_TYPE_LIST(V) \ |
| 647 | V(HeapNumber) \ |
| 648 | V(String) \ |
| 649 | V(Symbol) \ |
| 650 | V(SeqString) \ |
| 651 | V(ExternalString) \ |
| 652 | V(ConsString) \ |
| 653 | V(ExternalTwoByteString) \ |
| 654 | V(ExternalAsciiString) \ |
| 655 | V(SeqTwoByteString) \ |
| 656 | V(SeqAsciiString) \ |
| 657 | \ |
| 658 | V(PixelArray) \ |
| 659 | V(ExternalArray) \ |
| 660 | V(ExternalByteArray) \ |
| 661 | V(ExternalUnsignedByteArray) \ |
| 662 | V(ExternalShortArray) \ |
| 663 | V(ExternalUnsignedShortArray) \ |
| 664 | V(ExternalIntArray) \ |
| 665 | V(ExternalUnsignedIntArray) \ |
| 666 | V(ExternalFloatArray) \ |
| 667 | V(ByteArray) \ |
| 668 | V(JSObject) \ |
| 669 | V(JSContextExtensionObject) \ |
| 670 | V(Map) \ |
| 671 | V(DescriptorArray) \ |
| 672 | V(DeoptimizationInputData) \ |
| 673 | V(DeoptimizationOutputData) \ |
| 674 | V(FixedArray) \ |
| 675 | V(Context) \ |
| 676 | V(CatchContext) \ |
| 677 | V(GlobalContext) \ |
| 678 | V(JSFunction) \ |
| 679 | V(Code) \ |
| 680 | V(Oddball) \ |
| 681 | V(SharedFunctionInfo) \ |
| 682 | V(JSValue) \ |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 683 | V(JSMessageObject) \ |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 684 | V(StringWrapper) \ |
| 685 | V(Proxy) \ |
| 686 | V(Boolean) \ |
| 687 | V(JSArray) \ |
| 688 | V(JSRegExp) \ |
| 689 | V(HashTable) \ |
| 690 | V(Dictionary) \ |
| 691 | V(SymbolTable) \ |
| 692 | V(JSFunctionResultCache) \ |
| 693 | V(NormalizedMapCache) \ |
| 694 | V(CompilationCacheTable) \ |
| 695 | V(CodeCacheHashTable) \ |
| 696 | V(MapCache) \ |
| 697 | V(Primitive) \ |
| 698 | V(GlobalObject) \ |
| 699 | V(JSGlobalObject) \ |
| 700 | V(JSBuiltinsObject) \ |
| 701 | V(JSGlobalProxy) \ |
| 702 | V(UndetectableObject) \ |
| 703 | V(AccessCheckNeeded) \ |
| 704 | V(JSGlobalPropertyCell) \ |
| 705 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 706 | // Object is the abstract superclass for all classes in the |
| 707 | // object hierarchy. |
| 708 | // Object does not use any virtual functions to avoid the |
| 709 | // allocation of the C++ vtable. |
| 710 | // Since Smi and Failure are subclasses of Object no |
| 711 | // data members can be present in Object. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 712 | class Object : public MaybeObject { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 713 | public: |
| 714 | // Type testing. |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 715 | #define IS_TYPE_FUNCTION_DECL(type_) inline bool Is##type_(); |
| 716 | OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL) |
| 717 | HEAP_OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL) |
| 718 | #undef IS_TYPE_FUNCTION_DECL |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 719 | |
| 720 | // Returns true if this object is an instance of the specified |
| 721 | // function template. |
| 722 | inline bool IsInstanceOf(FunctionTemplateInfo* type); |
| 723 | |
| 724 | inline bool IsStruct(); |
| 725 | #define DECLARE_STRUCT_PREDICATE(NAME, Name, name) inline bool Is##Name(); |
| 726 | STRUCT_LIST(DECLARE_STRUCT_PREDICATE) |
| 727 | #undef DECLARE_STRUCT_PREDICATE |
| 728 | |
| 729 | // Oddball testing. |
| 730 | INLINE(bool IsUndefined()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 731 | INLINE(bool IsNull()); |
| 732 | INLINE(bool IsTrue()); |
| 733 | INLINE(bool IsFalse()); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 734 | inline bool IsArgumentsMarker(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 735 | |
| 736 | // Extract the number. |
| 737 | inline double Number(); |
| 738 | |
| 739 | inline bool HasSpecificClassOf(String* name); |
| 740 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 741 | MUST_USE_RESULT MaybeObject* ToObject(); // ECMA-262 9.9. |
| 742 | Object* ToBoolean(); // ECMA-262 9.2. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 743 | |
| 744 | // Convert to a JSObject if needed. |
| 745 | // global_context is used when creating wrapper object. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 746 | MUST_USE_RESULT MaybeObject* ToObject(Context* global_context); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 747 | |
| 748 | // Converts this to a Smi if possible. |
| 749 | // Failure is returned otherwise. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 750 | MUST_USE_RESULT inline MaybeObject* ToSmi(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 751 | |
| 752 | void Lookup(String* name, LookupResult* result); |
| 753 | |
| 754 | // Property access. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 755 | MUST_USE_RESULT inline MaybeObject* GetProperty(String* key); |
| 756 | MUST_USE_RESULT inline MaybeObject* GetProperty( |
| 757 | String* key, |
| 758 | PropertyAttributes* attributes); |
| 759 | MUST_USE_RESULT MaybeObject* GetPropertyWithReceiver( |
| 760 | Object* receiver, |
| 761 | String* key, |
| 762 | PropertyAttributes* attributes); |
| 763 | MUST_USE_RESULT MaybeObject* GetProperty(Object* receiver, |
| 764 | LookupResult* result, |
| 765 | String* key, |
| 766 | PropertyAttributes* attributes); |
| 767 | MUST_USE_RESULT MaybeObject* GetPropertyWithCallback(Object* receiver, |
| 768 | Object* structure, |
| 769 | String* name, |
| 770 | Object* holder); |
| 771 | MUST_USE_RESULT MaybeObject* GetPropertyWithDefinedGetter(Object* receiver, |
| 772 | JSFunction* getter); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 773 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 774 | inline MaybeObject* GetElement(uint32_t index); |
| 775 | // For use when we know that no exception can be thrown. |
| 776 | inline Object* GetElementNoExceptionThrown(uint32_t index); |
| 777 | MaybeObject* GetElementWithReceiver(Object* receiver, uint32_t index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 778 | |
| 779 | // Return the object's prototype (might be Heap::null_value()). |
| 780 | Object* GetPrototype(); |
| 781 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 782 | // Tries to convert an object to an array index. Returns true and sets |
| 783 | // the output parameter if it succeeds. |
| 784 | inline bool ToArrayIndex(uint32_t* index); |
| 785 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 786 | // Returns true if this is a JSValue containing a string and the index is |
| 787 | // < the length of the string. Used to implement [] on strings. |
| 788 | inline bool IsStringObjectWithCharacterAt(uint32_t index); |
| 789 | |
| 790 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 791 | // Verify a pointer is a valid object pointer. |
| 792 | static void VerifyPointer(Object* p); |
| 793 | #endif |
| 794 | |
| 795 | // Prints this object without details. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 796 | inline void ShortPrint() { |
| 797 | ShortPrint(stdout); |
| 798 | } |
| 799 | void ShortPrint(FILE* out); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 800 | |
| 801 | // Prints this object without details to a message accumulator. |
| 802 | void ShortPrint(StringStream* accumulator); |
| 803 | |
| 804 | // Casting: This cast is only needed to satisfy macros in objects-inl.h. |
| 805 | static Object* cast(Object* value) { return value; } |
| 806 | |
| 807 | // Layout description. |
| 808 | static const int kHeaderSize = 0; // Object does not take up any space. |
| 809 | |
| 810 | private: |
| 811 | DISALLOW_IMPLICIT_CONSTRUCTORS(Object); |
| 812 | }; |
| 813 | |
| 814 | |
| 815 | // Smi represents integer Numbers that can be stored in 31 bits. |
| 816 | // Smis are immediate which means they are NOT allocated in the heap. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 817 | // The this pointer has the following format: [31 bit signed int] 0 |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 818 | // For long smis it has the following format: |
| 819 | // [32 bit signed int] [31 bits zero padding] 0 |
| 820 | // Smi stands for small integer. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 821 | class Smi: public Object { |
| 822 | public: |
| 823 | // Returns the integer value. |
| 824 | inline int value(); |
| 825 | |
| 826 | // Convert a value to a Smi object. |
| 827 | static inline Smi* FromInt(int value); |
| 828 | |
| 829 | static inline Smi* FromIntptr(intptr_t value); |
| 830 | |
| 831 | // Returns whether value can be represented in a Smi. |
| 832 | static inline bool IsValid(intptr_t value); |
| 833 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 834 | // Casting. |
| 835 | static inline Smi* cast(Object* object); |
| 836 | |
| 837 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 838 | inline void SmiPrint() { |
| 839 | SmiPrint(stdout); |
| 840 | } |
| 841 | void SmiPrint(FILE* out); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 842 | void SmiPrint(StringStream* accumulator); |
| 843 | #ifdef DEBUG |
| 844 | void SmiVerify(); |
| 845 | #endif |
| 846 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 847 | static const int kMinValue = (-1 << (kSmiValueSize - 1)); |
| 848 | static const int kMaxValue = -(kMinValue + 1); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 849 | |
| 850 | private: |
| 851 | DISALLOW_IMPLICIT_CONSTRUCTORS(Smi); |
| 852 | }; |
| 853 | |
| 854 | |
| 855 | // Failure is used for reporting out of memory situations and |
| 856 | // propagating exceptions through the runtime system. Failure objects |
| 857 | // are transient and cannot occur as part of the object graph. |
| 858 | // |
| 859 | // Failures are a single word, encoded as follows: |
| 860 | // +-------------------------+---+--+--+ |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 861 | // |.........unused..........|sss|tt|11| |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 862 | // +-------------------------+---+--+--+ |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 863 | // 7 6 4 32 10 |
| 864 | // |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 865 | // |
| 866 | // The low two bits, 0-1, are the failure tag, 11. The next two bits, |
| 867 | // 2-3, are a failure type tag 'tt' with possible values: |
| 868 | // 00 RETRY_AFTER_GC |
| 869 | // 01 EXCEPTION |
| 870 | // 10 INTERNAL_ERROR |
| 871 | // 11 OUT_OF_MEMORY_EXCEPTION |
| 872 | // |
| 873 | // The next three bits, 4-6, are an allocation space tag 'sss'. The |
| 874 | // allocation space tag is 000 for all failure types except |
| 875 | // RETRY_AFTER_GC. For RETRY_AFTER_GC, the possible values are the |
| 876 | // allocation spaces (the encoding is found in globals.h). |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 877 | |
| 878 | // Failure type tag info. |
| 879 | const int kFailureTypeTagSize = 2; |
| 880 | const int kFailureTypeTagMask = (1 << kFailureTypeTagSize) - 1; |
| 881 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 882 | class Failure: public MaybeObject { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 883 | public: |
| 884 | // RuntimeStubs assumes EXCEPTION = 1 in the compiler-generated code. |
| 885 | enum Type { |
| 886 | RETRY_AFTER_GC = 0, |
| 887 | EXCEPTION = 1, // Returning this marker tells the real exception |
| 888 | // is in Top::pending_exception. |
| 889 | INTERNAL_ERROR = 2, |
| 890 | OUT_OF_MEMORY_EXCEPTION = 3 |
| 891 | }; |
| 892 | |
| 893 | inline Type type() const; |
| 894 | |
| 895 | // Returns the space that needs to be collected for RetryAfterGC failures. |
| 896 | inline AllocationSpace allocation_space() const; |
| 897 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 898 | inline bool IsInternalError() const; |
| 899 | inline bool IsOutOfMemoryException() const; |
| 900 | |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 901 | static inline Failure* RetryAfterGC(AllocationSpace space); |
| 902 | static inline Failure* RetryAfterGC(); // NEW_SPACE |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 903 | static inline Failure* Exception(); |
| 904 | static inline Failure* InternalError(); |
| 905 | static inline Failure* OutOfMemoryException(); |
| 906 | // Casting. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 907 | static inline Failure* cast(MaybeObject* object); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 908 | |
| 909 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 910 | inline void FailurePrint() { |
| 911 | FailurePrint(stdout); |
| 912 | } |
| 913 | void FailurePrint(FILE* out); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 914 | void FailurePrint(StringStream* accumulator); |
| 915 | #ifdef DEBUG |
| 916 | void FailureVerify(); |
| 917 | #endif |
| 918 | |
| 919 | private: |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 920 | inline intptr_t value() const; |
| 921 | static inline Failure* Construct(Type type, intptr_t value = 0); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 922 | |
| 923 | DISALLOW_IMPLICIT_CONSTRUCTORS(Failure); |
| 924 | }; |
| 925 | |
| 926 | |
| 927 | // Heap objects typically have a map pointer in their first word. However, |
| 928 | // during GC other data (eg, mark bits, forwarding addresses) is sometimes |
| 929 | // encoded in the first word. The class MapWord is an abstraction of the |
| 930 | // value in a heap object's first word. |
| 931 | class MapWord BASE_EMBEDDED { |
| 932 | public: |
| 933 | // Normal state: the map word contains a map pointer. |
| 934 | |
| 935 | // Create a map word from a map pointer. |
| 936 | static inline MapWord FromMap(Map* map); |
| 937 | |
| 938 | // View this map word as a map pointer. |
| 939 | inline Map* ToMap(); |
| 940 | |
| 941 | |
| 942 | // Scavenge collection: the map word of live objects in the from space |
| 943 | // contains a forwarding address (a heap object pointer in the to space). |
| 944 | |
| 945 | // True if this map word is a forwarding address for a scavenge |
| 946 | // collection. Only valid during a scavenge collection (specifically, |
| 947 | // when all map words are heap object pointers, ie. not during a full GC). |
| 948 | inline bool IsForwardingAddress(); |
| 949 | |
| 950 | // Create a map word from a forwarding address. |
| 951 | static inline MapWord FromForwardingAddress(HeapObject* object); |
| 952 | |
| 953 | // View this map word as a forwarding address. |
| 954 | inline HeapObject* ToForwardingAddress(); |
| 955 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 956 | // Marking phase of full collection: the map word of live objects is |
| 957 | // marked, and may be marked as overflowed (eg, the object is live, its |
| 958 | // children have not been visited, and it does not fit in the marking |
| 959 | // stack). |
| 960 | |
| 961 | // True if this map word's mark bit is set. |
| 962 | inline bool IsMarked(); |
| 963 | |
| 964 | // Return this map word but with its mark bit set. |
| 965 | inline void SetMark(); |
| 966 | |
| 967 | // Return this map word but with its mark bit cleared. |
| 968 | inline void ClearMark(); |
| 969 | |
| 970 | // True if this map word's overflow bit is set. |
| 971 | inline bool IsOverflowed(); |
| 972 | |
| 973 | // Return this map word but with its overflow bit set. |
| 974 | inline void SetOverflow(); |
| 975 | |
| 976 | // Return this map word but with its overflow bit cleared. |
| 977 | inline void ClearOverflow(); |
| 978 | |
| 979 | |
| 980 | // Compacting phase of a full compacting collection: the map word of live |
| 981 | // objects contains an encoding of the original map address along with the |
| 982 | // forwarding address (represented as an offset from the first live object |
| 983 | // in the same page as the (old) object address). |
| 984 | |
| 985 | // Create a map word from a map address and a forwarding address offset. |
| 986 | static inline MapWord EncodeAddress(Address map_address, int offset); |
| 987 | |
| 988 | // Return the map address encoded in this map word. |
| 989 | inline Address DecodeMapAddress(MapSpace* map_space); |
| 990 | |
| 991 | // Return the forwarding offset encoded in this map word. |
| 992 | inline int DecodeOffset(); |
| 993 | |
| 994 | |
| 995 | // During serialization: the map word is used to hold an encoded |
| 996 | // address, and possibly a mark bit (set and cleared with SetMark |
| 997 | // and ClearMark). |
| 998 | |
| 999 | // Create a map word from an encoded address. |
| 1000 | static inline MapWord FromEncodedAddress(Address address); |
| 1001 | |
| 1002 | inline Address ToEncodedAddress(); |
| 1003 | |
| 1004 | // Bits used by the marking phase of the garbage collector. |
| 1005 | // |
| 1006 | // The first word of a heap object is normally a map pointer. The last two |
| 1007 | // bits are tagged as '01' (kHeapObjectTag). We reuse the last two bits to |
| 1008 | // mark an object as live and/or overflowed: |
| 1009 | // last bit = 0, marked as alive |
| 1010 | // second bit = 1, overflowed |
| 1011 | // An object is only marked as overflowed when it is marked as live while |
| 1012 | // the marking stack is overflowed. |
| 1013 | static const int kMarkingBit = 0; // marking bit |
| 1014 | static const int kMarkingMask = (1 << kMarkingBit); // marking mask |
| 1015 | static const int kOverflowBit = 1; // overflow bit |
| 1016 | static const int kOverflowMask = (1 << kOverflowBit); // overflow mask |
| 1017 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1018 | // Forwarding pointers and map pointer encoding. On 32 bit all the bits are |
| 1019 | // used. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1020 | // +-----------------+------------------+-----------------+ |
| 1021 | // |forwarding offset|page offset of map|page index of map| |
| 1022 | // +-----------------+------------------+-----------------+ |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1023 | // ^ ^ ^ |
| 1024 | // | | | |
| 1025 | // | | kMapPageIndexBits |
| 1026 | // | kMapPageOffsetBits |
| 1027 | // kForwardingOffsetBits |
| 1028 | static const int kMapPageOffsetBits = kPageSizeBits - kMapAlignmentBits; |
| 1029 | static const int kForwardingOffsetBits = kPageSizeBits - kObjectAlignmentBits; |
| 1030 | #ifdef V8_HOST_ARCH_64_BIT |
| 1031 | static const int kMapPageIndexBits = 16; |
| 1032 | #else |
| 1033 | // Use all the 32-bits to encode on a 32-bit platform. |
| 1034 | static const int kMapPageIndexBits = |
| 1035 | 32 - (kMapPageOffsetBits + kForwardingOffsetBits); |
| 1036 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1037 | |
| 1038 | static const int kMapPageIndexShift = 0; |
| 1039 | static const int kMapPageOffsetShift = |
| 1040 | kMapPageIndexShift + kMapPageIndexBits; |
| 1041 | static const int kForwardingOffsetShift = |
| 1042 | kMapPageOffsetShift + kMapPageOffsetBits; |
| 1043 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1044 | // Bit masks covering the different parts the encoding. |
| 1045 | static const uintptr_t kMapPageIndexMask = |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1046 | (1 << kMapPageOffsetShift) - 1; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1047 | static const uintptr_t kMapPageOffsetMask = |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1048 | ((1 << kForwardingOffsetShift) - 1) & ~kMapPageIndexMask; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1049 | static const uintptr_t kForwardingOffsetMask = |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1050 | ~(kMapPageIndexMask | kMapPageOffsetMask); |
| 1051 | |
| 1052 | private: |
| 1053 | // HeapObject calls the private constructor and directly reads the value. |
| 1054 | friend class HeapObject; |
| 1055 | |
| 1056 | explicit MapWord(uintptr_t value) : value_(value) {} |
| 1057 | |
| 1058 | uintptr_t value_; |
| 1059 | }; |
| 1060 | |
| 1061 | |
| 1062 | // HeapObject is the superclass for all classes describing heap allocated |
| 1063 | // objects. |
| 1064 | class HeapObject: public Object { |
| 1065 | public: |
| 1066 | // [map]: Contains a map which contains the object's reflective |
| 1067 | // information. |
| 1068 | inline Map* map(); |
| 1069 | inline void set_map(Map* value); |
| 1070 | |
| 1071 | // During garbage collection, the map word of a heap object does not |
| 1072 | // necessarily contain a map pointer. |
| 1073 | inline MapWord map_word(); |
| 1074 | inline void set_map_word(MapWord map_word); |
| 1075 | |
| 1076 | // Converts an address to a HeapObject pointer. |
| 1077 | static inline HeapObject* FromAddress(Address address); |
| 1078 | |
| 1079 | // Returns the address of this HeapObject. |
| 1080 | inline Address address(); |
| 1081 | |
| 1082 | // Iterates over pointers contained in the object (including the Map) |
| 1083 | void Iterate(ObjectVisitor* v); |
| 1084 | |
| 1085 | // Iterates over all pointers contained in the object except the |
| 1086 | // first map pointer. The object type is given in the first |
| 1087 | // parameter. This function does not access the map pointer in the |
| 1088 | // object, and so is safe to call while the map pointer is modified. |
| 1089 | void IterateBody(InstanceType type, int object_size, ObjectVisitor* v); |
| 1090 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1091 | // Returns the heap object's size in bytes |
| 1092 | inline int Size(); |
| 1093 | |
| 1094 | // Given a heap object's map pointer, returns the heap size in bytes |
| 1095 | // Useful when the map pointer field is used for other purposes. |
| 1096 | // GC internal. |
| 1097 | inline int SizeFromMap(Map* map); |
| 1098 | |
| 1099 | // Support for the marking heap objects during the marking phase of GC. |
| 1100 | // True if the object is marked live. |
| 1101 | inline bool IsMarked(); |
| 1102 | |
| 1103 | // Mutate this object's map pointer to indicate that the object is live. |
| 1104 | inline void SetMark(); |
| 1105 | |
| 1106 | // Mutate this object's map pointer to remove the indication that the |
| 1107 | // object is live (ie, partially restore the map pointer). |
| 1108 | inline void ClearMark(); |
| 1109 | |
| 1110 | // True if this object is marked as overflowed. Overflowed objects have |
| 1111 | // been reached and marked during marking of the heap, but their children |
| 1112 | // have not necessarily been marked and they have not been pushed on the |
| 1113 | // marking stack. |
| 1114 | inline bool IsOverflowed(); |
| 1115 | |
| 1116 | // Mutate this object's map pointer to indicate that the object is |
| 1117 | // overflowed. |
| 1118 | inline void SetOverflow(); |
| 1119 | |
| 1120 | // Mutate this object's map pointer to remove the indication that the |
| 1121 | // object is overflowed (ie, partially restore the map pointer). |
| 1122 | inline void ClearOverflow(); |
| 1123 | |
| 1124 | // Returns the field at offset in obj, as a read/write Object* reference. |
| 1125 | // 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] | 1126 | // Does not invoke write barrier, so should only be assigned to |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1127 | // during marking GC. |
| 1128 | static inline Object** RawField(HeapObject* obj, int offset); |
| 1129 | |
| 1130 | // Casting. |
| 1131 | static inline HeapObject* cast(Object* obj); |
| 1132 | |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 1133 | // Return the write barrier mode for this. Callers of this function |
| 1134 | // must be able to present a reference to an AssertNoAllocation |
| 1135 | // object as a sign that they are not going to use this function |
| 1136 | // from code that allocates and thus invalidates the returned write |
| 1137 | // barrier mode. |
| 1138 | inline WriteBarrierMode GetWriteBarrierMode(const AssertNoAllocation&); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1139 | |
| 1140 | // Dispatched behavior. |
| 1141 | void HeapObjectShortPrint(StringStream* accumulator); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1142 | #ifdef OBJECT_PRINT |
| 1143 | inline void HeapObjectPrint() { |
| 1144 | HeapObjectPrint(stdout); |
| 1145 | } |
| 1146 | void HeapObjectPrint(FILE* out); |
| 1147 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1148 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1149 | void HeapObjectVerify(); |
| 1150 | inline void VerifyObjectField(int offset); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1151 | inline void VerifySmiField(int offset); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1152 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1153 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1154 | #ifdef OBJECT_PRINT |
| 1155 | void PrintHeader(FILE* out, const char* id); |
| 1156 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1157 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1158 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1159 | // Verify a pointer is a valid HeapObject pointer that points to object |
| 1160 | // areas in the heap. |
| 1161 | static void VerifyHeapPointer(Object* p); |
| 1162 | #endif |
| 1163 | |
| 1164 | // Layout description. |
| 1165 | // First field in a heap object is map. |
| 1166 | static const int kMapOffset = Object::kHeaderSize; |
| 1167 | static const int kHeaderSize = kMapOffset + kPointerSize; |
| 1168 | |
| 1169 | STATIC_CHECK(kMapOffset == Internals::kHeapObjectMapOffset); |
| 1170 | |
| 1171 | protected: |
| 1172 | // helpers for calling an ObjectVisitor to iterate over pointers in the |
| 1173 | // half-open range [start, end) specified as integer offsets |
| 1174 | inline void IteratePointers(ObjectVisitor* v, int start, int end); |
| 1175 | // as above, for the single element at "offset" |
| 1176 | inline void IteratePointer(ObjectVisitor* v, int offset); |
| 1177 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1178 | private: |
| 1179 | DISALLOW_IMPLICIT_CONSTRUCTORS(HeapObject); |
| 1180 | }; |
| 1181 | |
| 1182 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1183 | #define SLOT_ADDR(obj, offset) \ |
| 1184 | reinterpret_cast<Object**>((obj)->address() + offset) |
| 1185 | |
| 1186 | // This class describes a body of an object of a fixed size |
| 1187 | // in which all pointer fields are located in the [start_offset, end_offset) |
| 1188 | // interval. |
| 1189 | template<int start_offset, int end_offset, int size> |
| 1190 | class FixedBodyDescriptor { |
| 1191 | public: |
| 1192 | static const int kStartOffset = start_offset; |
| 1193 | static const int kEndOffset = end_offset; |
| 1194 | static const int kSize = size; |
| 1195 | |
| 1196 | static inline void IterateBody(HeapObject* obj, ObjectVisitor* v); |
| 1197 | |
| 1198 | template<typename StaticVisitor> |
| 1199 | static inline void IterateBody(HeapObject* obj) { |
| 1200 | StaticVisitor::VisitPointers(SLOT_ADDR(obj, start_offset), |
| 1201 | SLOT_ADDR(obj, end_offset)); |
| 1202 | } |
| 1203 | }; |
| 1204 | |
| 1205 | |
| 1206 | // This class describes a body of an object of a variable size |
| 1207 | // in which all pointer fields are located in the [start_offset, object_size) |
| 1208 | // interval. |
| 1209 | template<int start_offset> |
| 1210 | class FlexibleBodyDescriptor { |
| 1211 | public: |
| 1212 | static const int kStartOffset = start_offset; |
| 1213 | |
| 1214 | static inline void IterateBody(HeapObject* obj, |
| 1215 | int object_size, |
| 1216 | ObjectVisitor* v); |
| 1217 | |
| 1218 | template<typename StaticVisitor> |
| 1219 | static inline void IterateBody(HeapObject* obj, int object_size) { |
| 1220 | StaticVisitor::VisitPointers(SLOT_ADDR(obj, start_offset), |
| 1221 | SLOT_ADDR(obj, object_size)); |
| 1222 | } |
| 1223 | }; |
| 1224 | |
| 1225 | #undef SLOT_ADDR |
| 1226 | |
| 1227 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1228 | // The HeapNumber class describes heap allocated numbers that cannot be |
| 1229 | // represented in a Smi (small integer) |
| 1230 | class HeapNumber: public HeapObject { |
| 1231 | public: |
| 1232 | // [value]: number value. |
| 1233 | inline double value(); |
| 1234 | inline void set_value(double value); |
| 1235 | |
| 1236 | // Casting. |
| 1237 | static inline HeapNumber* cast(Object* obj); |
| 1238 | |
| 1239 | // Dispatched behavior. |
| 1240 | Object* HeapNumberToBoolean(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1241 | inline void HeapNumberPrint() { |
| 1242 | HeapNumberPrint(stdout); |
| 1243 | } |
| 1244 | void HeapNumberPrint(FILE* out); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1245 | void HeapNumberPrint(StringStream* accumulator); |
| 1246 | #ifdef DEBUG |
| 1247 | void HeapNumberVerify(); |
| 1248 | #endif |
| 1249 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1250 | inline int get_exponent(); |
| 1251 | inline int get_sign(); |
| 1252 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1253 | // Layout description. |
| 1254 | static const int kValueOffset = HeapObject::kHeaderSize; |
| 1255 | // IEEE doubles are two 32 bit words. The first is just mantissa, the second |
| 1256 | // is a mixture of sign, exponent and mantissa. Our current platforms are all |
| 1257 | // little endian apart from non-EABI arm which is little endian with big |
| 1258 | // endian floating point word ordering! |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1259 | #if !defined(V8_HOST_ARCH_ARM) || defined(USE_ARM_EABI) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1260 | static const int kMantissaOffset = kValueOffset; |
| 1261 | static const int kExponentOffset = kValueOffset + 4; |
| 1262 | #else |
| 1263 | static const int kMantissaOffset = kValueOffset + 4; |
| 1264 | static const int kExponentOffset = kValueOffset; |
| 1265 | # define BIG_ENDIAN_FLOATING_POINT 1 |
| 1266 | #endif |
| 1267 | static const int kSize = kValueOffset + kDoubleSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1268 | static const uint32_t kSignMask = 0x80000000u; |
| 1269 | static const uint32_t kExponentMask = 0x7ff00000u; |
| 1270 | static const uint32_t kMantissaMask = 0xfffffu; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1271 | static const int kMantissaBits = 52; |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 1272 | static const int kExponentBits = 11; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1273 | static const int kExponentBias = 1023; |
| 1274 | static const int kExponentShift = 20; |
| 1275 | static const int kMantissaBitsInTopWord = 20; |
| 1276 | static const int kNonMantissaBitsInTopWord = 12; |
| 1277 | |
| 1278 | private: |
| 1279 | DISALLOW_IMPLICIT_CONSTRUCTORS(HeapNumber); |
| 1280 | }; |
| 1281 | |
| 1282 | |
| 1283 | // The JSObject describes real heap allocated JavaScript objects with |
| 1284 | // properties. |
| 1285 | // Note that the map of JSObject changes during execution to enable inline |
| 1286 | // caching. |
| 1287 | class JSObject: public HeapObject { |
| 1288 | public: |
| 1289 | enum DeleteMode { NORMAL_DELETION, FORCE_DELETION }; |
| 1290 | enum ElementsKind { |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1291 | // The only "fast" kind. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1292 | FAST_ELEMENTS, |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1293 | // All the kinds below are "slow". |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1294 | DICTIONARY_ELEMENTS, |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1295 | PIXEL_ELEMENTS, |
| 1296 | EXTERNAL_BYTE_ELEMENTS, |
| 1297 | EXTERNAL_UNSIGNED_BYTE_ELEMENTS, |
| 1298 | EXTERNAL_SHORT_ELEMENTS, |
| 1299 | EXTERNAL_UNSIGNED_SHORT_ELEMENTS, |
| 1300 | EXTERNAL_INT_ELEMENTS, |
| 1301 | EXTERNAL_UNSIGNED_INT_ELEMENTS, |
| 1302 | EXTERNAL_FLOAT_ELEMENTS |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1303 | }; |
| 1304 | |
| 1305 | // [properties]: Backing storage for properties. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1306 | // 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] | 1307 | // slow case. |
| 1308 | DECL_ACCESSORS(properties, FixedArray) // Get and set fast properties. |
| 1309 | inline void initialize_properties(); |
| 1310 | inline bool HasFastProperties(); |
| 1311 | inline StringDictionary* property_dictionary(); // Gets slow properties. |
| 1312 | |
| 1313 | // [elements]: The elements (properties with names that are integers). |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1314 | // |
| 1315 | // Elements can be in two general modes: fast and slow. Each mode |
| 1316 | // corrensponds to a set of object representations of elements that |
| 1317 | // have something in common. |
| 1318 | // |
| 1319 | // In the fast mode elements is a FixedArray and so each element can |
| 1320 | // be quickly accessed. This fact is used in the generated code. The |
| 1321 | // elements array can have one of the two maps in this mode: |
| 1322 | // fixed_array_map or fixed_cow_array_map (for copy-on-write |
| 1323 | // arrays). In the latter case the elements array may be shared by a |
| 1324 | // few objects and so before writing to any element the array must |
| 1325 | // be copied. Use EnsureWritableFastElements in this case. |
| 1326 | // |
| 1327 | // In the slow mode elements is either a NumberDictionary or a |
| 1328 | // PixelArray or an ExternalArray. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1329 | DECL_ACCESSORS(elements, HeapObject) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1330 | inline void initialize_elements(); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1331 | MUST_USE_RESULT inline MaybeObject* ResetElements(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1332 | inline ElementsKind GetElementsKind(); |
| 1333 | inline bool HasFastElements(); |
| 1334 | inline bool HasDictionaryElements(); |
| 1335 | inline bool HasPixelElements(); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1336 | inline bool HasExternalArrayElements(); |
| 1337 | inline bool HasExternalByteElements(); |
| 1338 | inline bool HasExternalUnsignedByteElements(); |
| 1339 | inline bool HasExternalShortElements(); |
| 1340 | inline bool HasExternalUnsignedShortElements(); |
| 1341 | inline bool HasExternalIntElements(); |
| 1342 | inline bool HasExternalUnsignedIntElements(); |
| 1343 | inline bool HasExternalFloatElements(); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1344 | inline bool AllowsSetElementsLength(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1345 | inline NumberDictionary* element_dictionary(); // Gets slow elements. |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1346 | // Requires: this->HasFastElements(). |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1347 | MUST_USE_RESULT inline MaybeObject* EnsureWritableFastElements(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1348 | |
| 1349 | // Collects elements starting at index 0. |
| 1350 | // Undefined values are placed after non-undefined values. |
| 1351 | // Returns the number of non-undefined values. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1352 | MUST_USE_RESULT MaybeObject* PrepareElementsForSort(uint32_t limit); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1353 | // As PrepareElementsForSort, but only on objects where elements is |
| 1354 | // a dictionary, and it will stay a dictionary. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1355 | MUST_USE_RESULT MaybeObject* PrepareSlowElementsForSort(uint32_t limit); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1356 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1357 | MUST_USE_RESULT MaybeObject* SetProperty(String* key, |
| 1358 | Object* value, |
| 1359 | PropertyAttributes attributes); |
| 1360 | MUST_USE_RESULT MaybeObject* SetProperty(LookupResult* result, |
| 1361 | String* key, |
| 1362 | Object* value, |
| 1363 | PropertyAttributes attributes); |
| 1364 | MUST_USE_RESULT MaybeObject* SetPropertyWithFailedAccessCheck( |
| 1365 | LookupResult* result, |
| 1366 | String* name, |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 1367 | Object* value, |
| 1368 | bool check_prototype); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1369 | MUST_USE_RESULT MaybeObject* SetPropertyWithCallback(Object* structure, |
| 1370 | String* name, |
| 1371 | Object* value, |
| 1372 | JSObject* holder); |
| 1373 | MUST_USE_RESULT MaybeObject* SetPropertyWithDefinedSetter(JSFunction* setter, |
| 1374 | Object* value); |
| 1375 | MUST_USE_RESULT MaybeObject* SetPropertyWithInterceptor( |
| 1376 | String* name, |
| 1377 | Object* value, |
| 1378 | PropertyAttributes attributes); |
| 1379 | MUST_USE_RESULT MaybeObject* SetPropertyPostInterceptor( |
| 1380 | String* name, |
| 1381 | Object* value, |
| 1382 | PropertyAttributes attributes); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 1383 | MUST_USE_RESULT MaybeObject* SetLocalPropertyIgnoreAttributes( |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1384 | String* key, |
| 1385 | Object* value, |
| 1386 | PropertyAttributes attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1387 | |
| 1388 | // Retrieve a value in a normalized object given a lookup result. |
| 1389 | // Handles the special representation of JS global objects. |
| 1390 | Object* GetNormalizedProperty(LookupResult* result); |
| 1391 | |
| 1392 | // Sets the property value in a normalized object given a lookup result. |
| 1393 | // Handles the special representation of JS global objects. |
| 1394 | Object* SetNormalizedProperty(LookupResult* result, Object* value); |
| 1395 | |
| 1396 | // Sets the property value in a normalized object given (key, value, details). |
| 1397 | // Handles the special representation of JS global objects. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1398 | MUST_USE_RESULT MaybeObject* SetNormalizedProperty(String* name, |
| 1399 | Object* value, |
| 1400 | PropertyDetails details); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1401 | |
| 1402 | // Deletes the named property in a normalized object. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1403 | MUST_USE_RESULT MaybeObject* DeleteNormalizedProperty(String* name, |
| 1404 | DeleteMode mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1405 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1406 | // Returns the class name ([[Class]] property in the specification). |
| 1407 | String* class_name(); |
| 1408 | |
| 1409 | // Returns the constructor name (the name (possibly, inferred name) of the |
| 1410 | // function that was used to instantiate the object). |
| 1411 | String* constructor_name(); |
| 1412 | |
| 1413 | // Retrieve interceptors. |
| 1414 | InterceptorInfo* GetNamedInterceptor(); |
| 1415 | InterceptorInfo* GetIndexedInterceptor(); |
| 1416 | |
| 1417 | inline PropertyAttributes GetPropertyAttribute(String* name); |
| 1418 | PropertyAttributes GetPropertyAttributeWithReceiver(JSObject* receiver, |
| 1419 | String* name); |
| 1420 | PropertyAttributes GetLocalPropertyAttribute(String* name); |
| 1421 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1422 | MUST_USE_RESULT MaybeObject* DefineAccessor(String* name, |
| 1423 | bool is_getter, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1424 | Object* fun, |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1425 | PropertyAttributes attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1426 | Object* LookupAccessor(String* name, bool is_getter); |
| 1427 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1428 | MUST_USE_RESULT MaybeObject* DefineAccessor(AccessorInfo* info); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1429 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1430 | // Used from Object::GetProperty(). |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1431 | MaybeObject* GetPropertyWithFailedAccessCheck( |
| 1432 | Object* receiver, |
| 1433 | LookupResult* result, |
| 1434 | String* name, |
| 1435 | PropertyAttributes* attributes); |
| 1436 | MaybeObject* GetPropertyWithInterceptor( |
| 1437 | JSObject* receiver, |
| 1438 | String* name, |
| 1439 | PropertyAttributes* attributes); |
| 1440 | MaybeObject* GetPropertyPostInterceptor( |
| 1441 | JSObject* receiver, |
| 1442 | String* name, |
| 1443 | PropertyAttributes* attributes); |
| 1444 | MaybeObject* GetLocalPropertyPostInterceptor(JSObject* receiver, |
| 1445 | String* name, |
| 1446 | PropertyAttributes* attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1447 | |
| 1448 | // Returns true if this is an instance of an api function and has |
| 1449 | // been modified since it was created. May give false positives. |
| 1450 | bool IsDirty(); |
| 1451 | |
| 1452 | bool HasProperty(String* name) { |
| 1453 | return GetPropertyAttribute(name) != ABSENT; |
| 1454 | } |
| 1455 | |
| 1456 | // Can cause a GC if it hits an interceptor. |
| 1457 | bool HasLocalProperty(String* name) { |
| 1458 | return GetLocalPropertyAttribute(name) != ABSENT; |
| 1459 | } |
| 1460 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1461 | // If the receiver is a JSGlobalProxy this method will return its prototype, |
| 1462 | // otherwise the result is the receiver itself. |
| 1463 | inline Object* BypassGlobalProxy(); |
| 1464 | |
| 1465 | // Accessors for hidden properties object. |
| 1466 | // |
| 1467 | // Hidden properties are not local properties of the object itself. |
| 1468 | // Instead they are stored on an auxiliary JSObject stored as a local |
| 1469 | // property with a special name Heap::hidden_symbol(). But if the |
| 1470 | // receiver is a JSGlobalProxy then the auxiliary object is a property |
| 1471 | // of its prototype. |
| 1472 | // |
| 1473 | // Has/Get/SetHiddenPropertiesObject methods don't allow the holder to be |
| 1474 | // a JSGlobalProxy. Use BypassGlobalProxy method above to get to the real |
| 1475 | // holder. |
| 1476 | // |
| 1477 | // These accessors do not touch interceptors or accessors. |
| 1478 | inline bool HasHiddenPropertiesObject(); |
| 1479 | inline Object* GetHiddenPropertiesObject(); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1480 | MUST_USE_RESULT inline MaybeObject* SetHiddenPropertiesObject( |
| 1481 | Object* hidden_obj); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1482 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1483 | MUST_USE_RESULT MaybeObject* DeleteProperty(String* name, DeleteMode mode); |
| 1484 | MUST_USE_RESULT MaybeObject* DeleteElement(uint32_t index, DeleteMode mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1485 | |
| 1486 | // Tests for the fast common case for property enumeration. |
| 1487 | bool IsSimpleEnum(); |
| 1488 | |
| 1489 | // Do we want to keep the elements in fast case when increasing the |
| 1490 | // capacity? |
| 1491 | bool ShouldConvertToSlowElements(int new_capacity); |
| 1492 | // Returns true if the backing storage for the slow-case elements of |
| 1493 | // this object takes up nearly as much space as a fast-case backing |
| 1494 | // storage would. In that case the JSObject should have fast |
| 1495 | // elements. |
| 1496 | bool ShouldConvertToFastElements(); |
| 1497 | |
| 1498 | // Return the object's prototype (might be Heap::null_value()). |
| 1499 | inline Object* GetPrototype(); |
| 1500 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1501 | // Set the object's prototype (only JSObject and null are allowed). |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1502 | MUST_USE_RESULT MaybeObject* SetPrototype(Object* value, |
| 1503 | bool skip_hidden_prototypes); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1504 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1505 | // Tells whether the index'th element is present. |
| 1506 | inline bool HasElement(uint32_t index); |
| 1507 | bool HasElementWithReceiver(JSObject* receiver, uint32_t index); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1508 | |
| 1509 | // Tells whether the index'th element is present and how it is stored. |
| 1510 | enum LocalElementType { |
| 1511 | // There is no element with given index. |
| 1512 | UNDEFINED_ELEMENT, |
| 1513 | |
| 1514 | // Element with given index is handled by interceptor. |
| 1515 | INTERCEPTED_ELEMENT, |
| 1516 | |
| 1517 | // Element with given index is character in string. |
| 1518 | STRING_CHARACTER_ELEMENT, |
| 1519 | |
| 1520 | // Element with given index is stored in fast backing store. |
| 1521 | FAST_ELEMENT, |
| 1522 | |
| 1523 | // Element with given index is stored in slow backing store. |
| 1524 | DICTIONARY_ELEMENT |
| 1525 | }; |
| 1526 | |
| 1527 | LocalElementType HasLocalElement(uint32_t index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1528 | |
| 1529 | bool HasElementWithInterceptor(JSObject* receiver, uint32_t index); |
| 1530 | bool HasElementPostInterceptor(JSObject* receiver, uint32_t index); |
| 1531 | |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 1532 | MUST_USE_RESULT MaybeObject* SetFastElement(uint32_t index, |
| 1533 | Object* value, |
| 1534 | bool check_prototype = true); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1535 | |
| 1536 | // Set the index'th array element. |
| 1537 | // A Failure object is returned if GC is needed. |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 1538 | MUST_USE_RESULT MaybeObject* SetElement(uint32_t index, |
| 1539 | Object* value, |
| 1540 | bool check_prototype = true); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1541 | |
| 1542 | // Returns the index'th element. |
| 1543 | // The undefined object if index is out of bounds. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1544 | MaybeObject* GetElementWithReceiver(JSObject* receiver, uint32_t index); |
| 1545 | MaybeObject* GetElementWithInterceptor(JSObject* receiver, uint32_t index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1546 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1547 | MUST_USE_RESULT MaybeObject* SetFastElementsCapacityAndLength(int capacity, |
| 1548 | int length); |
| 1549 | MUST_USE_RESULT MaybeObject* SetSlowElements(Object* length); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1550 | |
| 1551 | // Lookup interceptors are used for handling properties controlled by host |
| 1552 | // objects. |
| 1553 | inline bool HasNamedInterceptor(); |
| 1554 | inline bool HasIndexedInterceptor(); |
| 1555 | |
| 1556 | // Support functions for v8 api (needed for correct interceptor behavior). |
| 1557 | bool HasRealNamedProperty(String* key); |
| 1558 | bool HasRealElementProperty(uint32_t index); |
| 1559 | bool HasRealNamedCallbackProperty(String* key); |
| 1560 | |
| 1561 | // Initializes the array to a certain length |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1562 | MUST_USE_RESULT MaybeObject* SetElementsLength(Object* length); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1563 | |
| 1564 | // Get the header size for a JSObject. Used to compute the index of |
| 1565 | // internal fields as well as the number of internal fields. |
| 1566 | inline int GetHeaderSize(); |
| 1567 | |
| 1568 | inline int GetInternalFieldCount(); |
| 1569 | inline Object* GetInternalField(int index); |
| 1570 | inline void SetInternalField(int index, Object* value); |
| 1571 | |
| 1572 | // Lookup a property. If found, the result is valid and has |
| 1573 | // detailed information. |
| 1574 | void LocalLookup(String* name, LookupResult* result); |
| 1575 | void Lookup(String* name, LookupResult* result); |
| 1576 | |
| 1577 | // The following lookup functions skip interceptors. |
| 1578 | void LocalLookupRealNamedProperty(String* name, LookupResult* result); |
| 1579 | void LookupRealNamedProperty(String* name, LookupResult* result); |
| 1580 | void LookupRealNamedPropertyInPrototypes(String* name, LookupResult* result); |
| 1581 | void LookupCallbackSetterInPrototypes(String* name, LookupResult* result); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 1582 | MUST_USE_RESULT MaybeObject* SetElementWithCallbackSetterInPrototypes( |
| 1583 | uint32_t index, Object* value, bool* found); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1584 | void LookupCallback(String* name, LookupResult* result); |
| 1585 | |
| 1586 | // Returns the number of properties on this object filtering out properties |
| 1587 | // with the specified attributes (ignoring interceptors). |
| 1588 | int NumberOfLocalProperties(PropertyAttributes filter); |
| 1589 | // Returns the number of enumerable properties (ignoring interceptors). |
| 1590 | int NumberOfEnumProperties(); |
| 1591 | // Fill in details for properties into storage starting at the specified |
| 1592 | // index. |
| 1593 | void GetLocalPropertyNames(FixedArray* storage, int index); |
| 1594 | |
| 1595 | // Returns the number of properties on this object filtering out properties |
| 1596 | // with the specified attributes (ignoring interceptors). |
| 1597 | int NumberOfLocalElements(PropertyAttributes filter); |
| 1598 | // Returns the number of enumerable elements (ignoring interceptors). |
| 1599 | int NumberOfEnumElements(); |
| 1600 | // Returns the number of elements on this object filtering out elements |
| 1601 | // with the specified attributes (ignoring interceptors). |
| 1602 | int GetLocalElementKeys(FixedArray* storage, PropertyAttributes filter); |
| 1603 | // Count and fill in the enumerable elements into storage. |
| 1604 | // (storage->length() == NumberOfEnumElements()). |
| 1605 | // If storage is NULL, will count the elements without adding |
| 1606 | // them to any storage. |
| 1607 | // Returns the number of enumerable elements. |
| 1608 | int GetEnumElementKeys(FixedArray* storage); |
| 1609 | |
| 1610 | // Add a property to a fast-case object using a map transition to |
| 1611 | // new_map. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1612 | MUST_USE_RESULT MaybeObject* AddFastPropertyUsingMap(Map* new_map, |
| 1613 | String* name, |
| 1614 | Object* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1615 | |
| 1616 | // Add a constant function property to a fast-case object. |
| 1617 | // This leaves a CONSTANT_TRANSITION in the old map, and |
| 1618 | // if it is called on a second object with this map, a |
| 1619 | // normal property is added instead, with a map transition. |
| 1620 | // This avoids the creation of many maps with the same constant |
| 1621 | // function, all orphaned. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1622 | MUST_USE_RESULT MaybeObject* AddConstantFunctionProperty( |
| 1623 | String* name, |
| 1624 | JSFunction* function, |
| 1625 | PropertyAttributes attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1626 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1627 | MUST_USE_RESULT MaybeObject* ReplaceSlowProperty( |
| 1628 | String* name, |
| 1629 | Object* value, |
| 1630 | PropertyAttributes attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1631 | |
| 1632 | // Converts a descriptor of any other type to a real field, |
| 1633 | // backed by the properties array. Descriptors of visible |
| 1634 | // types, such as CONSTANT_FUNCTION, keep their enumeration order. |
| 1635 | // Converts the descriptor on the original object's map to a |
| 1636 | // 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] | 1637 | MUST_USE_RESULT MaybeObject* ConvertDescriptorToFieldAndMapTransition( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1638 | String* name, |
| 1639 | Object* new_value, |
| 1640 | PropertyAttributes attributes); |
| 1641 | |
| 1642 | // Converts a descriptor of any other type to a real field, |
| 1643 | // backed by the properties array. Descriptors of visible |
| 1644 | // types, such as CONSTANT_FUNCTION, keep their enumeration order. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1645 | MUST_USE_RESULT MaybeObject* ConvertDescriptorToField( |
| 1646 | String* name, |
| 1647 | Object* new_value, |
| 1648 | PropertyAttributes attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1649 | |
| 1650 | // Add a property to a fast-case object. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1651 | MUST_USE_RESULT MaybeObject* AddFastProperty(String* name, |
| 1652 | Object* value, |
| 1653 | PropertyAttributes attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1654 | |
| 1655 | // Add a property to a slow-case object. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1656 | MUST_USE_RESULT MaybeObject* AddSlowProperty(String* name, |
| 1657 | Object* value, |
| 1658 | PropertyAttributes attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1659 | |
| 1660 | // Add a property to an object. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1661 | MUST_USE_RESULT MaybeObject* AddProperty(String* name, |
| 1662 | Object* value, |
| 1663 | PropertyAttributes attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1664 | |
| 1665 | // Convert the object to use the canonical dictionary |
| 1666 | // representation. If the object is expected to have additional properties |
| 1667 | // added this number can be indicated to have the backing store allocated to |
| 1668 | // an initial capacity for holding these properties. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1669 | MUST_USE_RESULT MaybeObject* NormalizeProperties( |
| 1670 | PropertyNormalizationMode mode, |
| 1671 | int expected_additional_properties); |
| 1672 | MUST_USE_RESULT MaybeObject* NormalizeElements(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1673 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1674 | MUST_USE_RESULT MaybeObject* UpdateMapCodeCache(String* name, Code* code); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1675 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1676 | // Transform slow named properties to fast variants. |
| 1677 | // Returns failure if allocation failed. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1678 | MUST_USE_RESULT MaybeObject* TransformToFastProperties( |
| 1679 | int unused_property_fields); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1680 | |
| 1681 | // Access fast-case object properties at index. |
| 1682 | inline Object* FastPropertyAt(int index); |
| 1683 | inline Object* FastPropertyAtPut(int index, Object* value); |
| 1684 | |
| 1685 | // Access to in object properties. |
| 1686 | inline Object* InObjectPropertyAt(int index); |
| 1687 | inline Object* InObjectPropertyAtPut(int index, |
| 1688 | Object* value, |
| 1689 | WriteBarrierMode mode |
| 1690 | = UPDATE_WRITE_BARRIER); |
| 1691 | |
| 1692 | // initializes the body after properties slot, properties slot is |
| 1693 | // initialized by set_properties |
| 1694 | // Note: this call does not update write barrier, it is caller's |
| 1695 | // reponsibility to ensure that *v* can be collected without WB here. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1696 | inline void InitializeBody(int object_size, Object* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1697 | |
| 1698 | // Check whether this object references another object |
| 1699 | bool ReferencesObject(Object* obj); |
| 1700 | |
| 1701 | // Casting. |
| 1702 | static inline JSObject* cast(Object* obj); |
| 1703 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1704 | // Disalow further properties to be added to the object. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1705 | MUST_USE_RESULT MaybeObject* PreventExtensions(); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1706 | |
| 1707 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1708 | // Dispatched behavior. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1709 | void JSObjectShortPrint(StringStream* accumulator); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1710 | #ifdef OBJECT_PRINT |
| 1711 | inline void JSObjectPrint() { |
| 1712 | JSObjectPrint(stdout); |
| 1713 | } |
| 1714 | void JSObjectPrint(FILE* out); |
| 1715 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1716 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1717 | void JSObjectVerify(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1718 | #endif |
| 1719 | #ifdef OBJECT_PRINT |
| 1720 | inline void PrintProperties() { |
| 1721 | PrintProperties(stdout); |
| 1722 | } |
| 1723 | void PrintProperties(FILE* out); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1724 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1725 | inline void PrintElements() { |
| 1726 | PrintElements(stdout); |
| 1727 | } |
| 1728 | void PrintElements(FILE* out); |
| 1729 | #endif |
| 1730 | |
| 1731 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1732 | // Structure for collecting spill information about JSObjects. |
| 1733 | class SpillInformation { |
| 1734 | public: |
| 1735 | void Clear(); |
| 1736 | void Print(); |
| 1737 | int number_of_objects_; |
| 1738 | int number_of_objects_with_fast_properties_; |
| 1739 | int number_of_objects_with_fast_elements_; |
| 1740 | int number_of_fast_used_fields_; |
| 1741 | int number_of_fast_unused_fields_; |
| 1742 | int number_of_slow_used_properties_; |
| 1743 | int number_of_slow_unused_properties_; |
| 1744 | int number_of_fast_used_elements_; |
| 1745 | int number_of_fast_unused_elements_; |
| 1746 | int number_of_slow_used_elements_; |
| 1747 | int number_of_slow_unused_elements_; |
| 1748 | }; |
| 1749 | |
| 1750 | void IncrementSpillStatistics(SpillInformation* info); |
| 1751 | #endif |
| 1752 | Object* SlowReverseLookup(Object* value); |
| 1753 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1754 | // Maximal number of fast properties for the JSObject. Used to |
| 1755 | // restrict the number of map transitions to avoid an explosion in |
| 1756 | // the number of maps for objects used as dictionaries. |
| 1757 | inline int MaxFastProperties(); |
| 1758 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1759 | // Maximal number of elements (numbered 0 .. kMaxElementCount - 1). |
| 1760 | // Also maximal value of JSArray's length property. |
| 1761 | static const uint32_t kMaxElementCount = 0xffffffffu; |
| 1762 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1763 | static const uint32_t kMaxGap = 1024; |
| 1764 | static const int kMaxFastElementsLength = 5000; |
| 1765 | static const int kInitialMaxFastElementArray = 100000; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1766 | static const int kMaxFastProperties = 12; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1767 | static const int kMaxInstanceSize = 255 * kPointerSize; |
| 1768 | // When extending the backing storage for property values, we increase |
| 1769 | // its size by more than the 1 entry necessary, so sequentially adding fields |
| 1770 | // to the same object requires fewer allocations and copies. |
| 1771 | static const int kFieldsAdded = 3; |
| 1772 | |
| 1773 | // Layout description. |
| 1774 | static const int kPropertiesOffset = HeapObject::kHeaderSize; |
| 1775 | static const int kElementsOffset = kPropertiesOffset + kPointerSize; |
| 1776 | static const int kHeaderSize = kElementsOffset + kPointerSize; |
| 1777 | |
| 1778 | STATIC_CHECK(kHeaderSize == Internals::kJSObjectHeaderSize); |
| 1779 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1780 | class BodyDescriptor : public FlexibleBodyDescriptor<kPropertiesOffset> { |
| 1781 | public: |
| 1782 | static inline int SizeOf(Map* map, HeapObject* object); |
| 1783 | }; |
| 1784 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1785 | private: |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1786 | MUST_USE_RESULT MaybeObject* GetElementWithCallback(Object* receiver, |
| 1787 | Object* structure, |
| 1788 | uint32_t index, |
| 1789 | Object* holder); |
| 1790 | MaybeObject* SetElementWithCallback(Object* structure, |
| 1791 | uint32_t index, |
| 1792 | Object* value, |
| 1793 | JSObject* holder); |
| 1794 | MUST_USE_RESULT MaybeObject* SetElementWithInterceptor(uint32_t index, |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 1795 | Object* value, |
| 1796 | bool check_prototype); |
| 1797 | MUST_USE_RESULT MaybeObject* SetElementWithoutInterceptor( |
| 1798 | uint32_t index, |
| 1799 | Object* value, |
| 1800 | bool check_prototype); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1801 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1802 | MaybeObject* GetElementPostInterceptor(JSObject* receiver, uint32_t index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1803 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1804 | MUST_USE_RESULT MaybeObject* DeletePropertyPostInterceptor(String* name, |
| 1805 | DeleteMode mode); |
| 1806 | MUST_USE_RESULT MaybeObject* DeletePropertyWithInterceptor(String* name); |
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* DeleteElementPostInterceptor(uint32_t index, |
| 1809 | DeleteMode mode); |
| 1810 | MUST_USE_RESULT MaybeObject* DeleteElementWithInterceptor(uint32_t index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1811 | |
| 1812 | PropertyAttributes GetPropertyAttributePostInterceptor(JSObject* receiver, |
| 1813 | String* name, |
| 1814 | bool continue_search); |
| 1815 | PropertyAttributes GetPropertyAttributeWithInterceptor(JSObject* receiver, |
| 1816 | String* name, |
| 1817 | bool continue_search); |
| 1818 | PropertyAttributes GetPropertyAttributeWithFailedAccessCheck( |
| 1819 | Object* receiver, |
| 1820 | LookupResult* result, |
| 1821 | String* name, |
| 1822 | bool continue_search); |
| 1823 | PropertyAttributes GetPropertyAttribute(JSObject* receiver, |
| 1824 | LookupResult* result, |
| 1825 | String* name, |
| 1826 | bool continue_search); |
| 1827 | |
| 1828 | // Returns true if most of the elements backing storage is used. |
| 1829 | bool HasDenseElements(); |
| 1830 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1831 | bool CanSetCallback(String* name); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1832 | MUST_USE_RESULT MaybeObject* SetElementCallback( |
| 1833 | uint32_t index, |
| 1834 | Object* structure, |
| 1835 | PropertyAttributes attributes); |
| 1836 | MUST_USE_RESULT MaybeObject* SetPropertyCallback( |
| 1837 | String* name, |
| 1838 | Object* structure, |
| 1839 | PropertyAttributes attributes); |
| 1840 | MUST_USE_RESULT MaybeObject* DefineGetterSetter( |
| 1841 | String* name, |
| 1842 | PropertyAttributes attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1843 | |
| 1844 | void LookupInDescriptor(String* name, LookupResult* result); |
| 1845 | |
| 1846 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSObject); |
| 1847 | }; |
| 1848 | |
| 1849 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1850 | // FixedArray describes fixed-sized arrays with element type Object*. |
| 1851 | class FixedArray: public HeapObject { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1852 | public: |
| 1853 | // [length]: length of the array. |
| 1854 | inline int length(); |
| 1855 | inline void set_length(int value); |
| 1856 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1857 | // Setter and getter for elements. |
| 1858 | inline Object* get(int index); |
| 1859 | // Setter that uses write barrier. |
| 1860 | inline void set(int index, Object* value); |
| 1861 | |
| 1862 | // Setter that doesn't need write barrier). |
| 1863 | inline void set(int index, Smi* value); |
| 1864 | // Setter with explicit barrier mode. |
| 1865 | inline void set(int index, Object* value, WriteBarrierMode mode); |
| 1866 | |
| 1867 | // Setters for frequently used oddballs located in old space. |
| 1868 | inline void set_undefined(int index); |
| 1869 | inline void set_null(int index); |
| 1870 | inline void set_the_hole(int index); |
| 1871 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1872 | // Setters with less debug checks for the GC to use. |
| 1873 | inline void set_unchecked(int index, Smi* value); |
| 1874 | inline void set_null_unchecked(int index); |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 1875 | inline void set_unchecked(int index, Object* value, WriteBarrierMode mode); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1876 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1877 | // Gives access to raw memory which stores the array's data. |
| 1878 | inline Object** data_start(); |
| 1879 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1880 | // Copy operations. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1881 | MUST_USE_RESULT inline MaybeObject* Copy(); |
| 1882 | MUST_USE_RESULT MaybeObject* CopySize(int new_length); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1883 | |
| 1884 | // Add the elements of a JSArray to this FixedArray. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1885 | MUST_USE_RESULT MaybeObject* AddKeysFromJSArray(JSArray* array); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1886 | |
| 1887 | // Compute the union of this and other. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 1888 | MUST_USE_RESULT MaybeObject* UnionOfKeys(FixedArray* other); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1889 | |
| 1890 | // Copy a sub array from the receiver to dest. |
| 1891 | void CopyTo(int pos, FixedArray* dest, int dest_pos, int len); |
| 1892 | |
| 1893 | // Garbage collection support. |
| 1894 | static int SizeFor(int length) { return kHeaderSize + length * kPointerSize; } |
| 1895 | |
| 1896 | // Code Generation support. |
| 1897 | static int OffsetOfElementAt(int index) { return SizeFor(index); } |
| 1898 | |
| 1899 | // Casting. |
| 1900 | static inline FixedArray* cast(Object* obj); |
| 1901 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1902 | // Layout description. |
| 1903 | // Length is smi tagged when it is stored. |
| 1904 | static const int kLengthOffset = HeapObject::kHeaderSize; |
| 1905 | static const int kHeaderSize = kLengthOffset + kPointerSize; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1906 | |
| 1907 | // Maximal allowed size, in bytes, of a single FixedArray. |
| 1908 | // Prevents overflowing size computations, as well as extreme memory |
| 1909 | // consumption. |
| 1910 | static const int kMaxSize = 512 * MB; |
| 1911 | // Maximally allowed length of a FixedArray. |
| 1912 | static const int kMaxLength = (kMaxSize - kHeaderSize) / kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1913 | |
| 1914 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1915 | #ifdef OBJECT_PRINT |
| 1916 | inline void FixedArrayPrint() { |
| 1917 | FixedArrayPrint(stdout); |
| 1918 | } |
| 1919 | void FixedArrayPrint(FILE* out); |
| 1920 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1921 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1922 | void FixedArrayVerify(); |
| 1923 | // Checks if two FixedArrays have identical contents. |
| 1924 | bool IsEqualTo(FixedArray* other); |
| 1925 | #endif |
| 1926 | |
| 1927 | // Swap two elements in a pair of arrays. If this array and the |
| 1928 | // numbers array are the same object, the elements are only swapped |
| 1929 | // once. |
| 1930 | void SwapPairs(FixedArray* numbers, int i, int j); |
| 1931 | |
| 1932 | // Sort prefix of this array and the numbers array as pairs wrt. the |
| 1933 | // numbers. If the numbers array and the this array are the same |
| 1934 | // object, the prefix of this array is sorted. |
| 1935 | void SortPairs(FixedArray* numbers, uint32_t len); |
| 1936 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 1937 | class BodyDescriptor : public FlexibleBodyDescriptor<kHeaderSize> { |
| 1938 | public: |
| 1939 | static inline int SizeOf(Map* map, HeapObject* object) { |
| 1940 | return SizeFor(reinterpret_cast<FixedArray*>(object)->length()); |
| 1941 | } |
| 1942 | }; |
| 1943 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1944 | protected: |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 1945 | // Set operation on FixedArray without using write barriers. Can |
| 1946 | // only be used for storing old space objects or smis. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1947 | static inline void fast_set(FixedArray* array, int index, Object* value); |
| 1948 | |
| 1949 | private: |
| 1950 | DISALLOW_IMPLICIT_CONSTRUCTORS(FixedArray); |
| 1951 | }; |
| 1952 | |
| 1953 | |
| 1954 | // DescriptorArrays are fixed arrays used to hold instance descriptors. |
| 1955 | // The format of the these objects is: |
| 1956 | // [0]: point to a fixed array with (value, detail) pairs. |
| 1957 | // [1]: next enumeration index (Smi), or pointer to small fixed array: |
| 1958 | // [0]: next enumeration index (Smi) |
| 1959 | // [1]: pointer to fixed array with enum cache |
| 1960 | // [2]: first key |
| 1961 | // [length() - 1]: last key |
| 1962 | // |
| 1963 | class DescriptorArray: public FixedArray { |
| 1964 | public: |
| 1965 | // Is this the singleton empty_descriptor_array? |
| 1966 | inline bool IsEmpty(); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1967 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1968 | // Returns the number of descriptors in the array. |
| 1969 | int number_of_descriptors() { |
| 1970 | return IsEmpty() ? 0 : length() - kFirstIndex; |
| 1971 | } |
| 1972 | |
| 1973 | int NextEnumerationIndex() { |
| 1974 | if (IsEmpty()) return PropertyDetails::kInitialIndex; |
| 1975 | Object* obj = get(kEnumerationIndexIndex); |
| 1976 | if (obj->IsSmi()) { |
| 1977 | return Smi::cast(obj)->value(); |
| 1978 | } else { |
| 1979 | Object* index = FixedArray::cast(obj)->get(kEnumCacheBridgeEnumIndex); |
| 1980 | return Smi::cast(index)->value(); |
| 1981 | } |
| 1982 | } |
| 1983 | |
| 1984 | // Set next enumeration index and flush any enum cache. |
| 1985 | void SetNextEnumerationIndex(int value) { |
| 1986 | if (!IsEmpty()) { |
| 1987 | fast_set(this, kEnumerationIndexIndex, Smi::FromInt(value)); |
| 1988 | } |
| 1989 | } |
| 1990 | bool HasEnumCache() { |
| 1991 | return !IsEmpty() && !get(kEnumerationIndexIndex)->IsSmi(); |
| 1992 | } |
| 1993 | |
| 1994 | Object* GetEnumCache() { |
| 1995 | ASSERT(HasEnumCache()); |
| 1996 | FixedArray* bridge = FixedArray::cast(get(kEnumerationIndexIndex)); |
| 1997 | return bridge->get(kEnumCacheBridgeCacheIndex); |
| 1998 | } |
| 1999 | |
| 2000 | // Initialize or change the enum cache, |
| 2001 | // using the supplied storage for the small "bridge". |
| 2002 | void SetEnumCache(FixedArray* bridge_storage, FixedArray* new_cache); |
| 2003 | |
| 2004 | // Accessors for fetching instance descriptor at descriptor number. |
| 2005 | inline String* GetKey(int descriptor_number); |
| 2006 | inline Object* GetValue(int descriptor_number); |
| 2007 | inline Smi* GetDetails(int descriptor_number); |
| 2008 | inline PropertyType GetType(int descriptor_number); |
| 2009 | inline int GetFieldIndex(int descriptor_number); |
| 2010 | inline JSFunction* GetConstantFunction(int descriptor_number); |
| 2011 | inline Object* GetCallbacksObject(int descriptor_number); |
| 2012 | inline AccessorDescriptor* GetCallbacks(int descriptor_number); |
| 2013 | inline bool IsProperty(int descriptor_number); |
| 2014 | inline bool IsTransition(int descriptor_number); |
| 2015 | inline bool IsNullDescriptor(int descriptor_number); |
| 2016 | inline bool IsDontEnum(int descriptor_number); |
| 2017 | |
| 2018 | // Accessor for complete descriptor. |
| 2019 | inline void Get(int descriptor_number, Descriptor* desc); |
| 2020 | inline void Set(int descriptor_number, Descriptor* desc); |
| 2021 | |
| 2022 | // Transfer complete descriptor from another descriptor array to |
| 2023 | // this one. |
| 2024 | inline void CopyFrom(int index, DescriptorArray* src, int src_index); |
| 2025 | |
| 2026 | // Copy the descriptor array, insert a new descriptor and optionally |
| 2027 | // remove map transitions. If the descriptor is already present, it is |
| 2028 | // replaced. If a replaced descriptor is a real property (not a transition |
| 2029 | // or null), its enumeration index is kept as is. |
| 2030 | // If adding a real property, map transitions must be removed. If adding |
| 2031 | // a transition, they must not be removed. All null descriptors are removed. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2032 | MUST_USE_RESULT MaybeObject* CopyInsert(Descriptor* descriptor, |
| 2033 | TransitionFlag transition_flag); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2034 | |
| 2035 | // Remove all transitions. Return a copy of the array with all transitions |
| 2036 | // 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] | 2037 | MUST_USE_RESULT MaybeObject* RemoveTransitions(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2038 | |
| 2039 | // Sort the instance descriptors by the hash codes of their keys. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 2040 | // Does not check for duplicates. |
| 2041 | void SortUnchecked(); |
| 2042 | |
| 2043 | // Sort the instance descriptors by the hash codes of their keys. |
| 2044 | // Checks the result for duplicates. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2045 | void Sort(); |
| 2046 | |
| 2047 | // Search the instance descriptors for given name. |
| 2048 | inline int Search(String* name); |
| 2049 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2050 | // As the above, but uses DescriptorLookupCache and updates it when |
| 2051 | // necessary. |
| 2052 | inline int SearchWithCache(String* name); |
| 2053 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2054 | // Tells whether the name is present int the array. |
| 2055 | bool Contains(String* name) { return kNotFound != Search(name); } |
| 2056 | |
| 2057 | // Perform a binary search in the instance descriptors represented |
| 2058 | // by this fixed array. low and high are descriptor indices. If there |
| 2059 | // are three instance descriptors in this array it should be called |
| 2060 | // with low=0 and high=2. |
| 2061 | int BinarySearch(String* name, int low, int high); |
| 2062 | |
| 2063 | // Perform a linear search in the instance descriptors represented |
| 2064 | // by this fixed array. len is the number of descriptor indices that are |
| 2065 | // valid. Does not require the descriptors to be sorted. |
| 2066 | int LinearSearch(String* name, int len); |
| 2067 | |
| 2068 | // Allocates a DescriptorArray, but returns the singleton |
| 2069 | // empty descriptor array object if number_of_descriptors is 0. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2070 | MUST_USE_RESULT static MaybeObject* Allocate(int number_of_descriptors); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2071 | |
| 2072 | // Casting. |
| 2073 | static inline DescriptorArray* cast(Object* obj); |
| 2074 | |
| 2075 | // Constant for denoting key was not found. |
| 2076 | static const int kNotFound = -1; |
| 2077 | |
| 2078 | static const int kContentArrayIndex = 0; |
| 2079 | static const int kEnumerationIndexIndex = 1; |
| 2080 | static const int kFirstIndex = 2; |
| 2081 | |
| 2082 | // The length of the "bridge" to the enum cache. |
| 2083 | static const int kEnumCacheBridgeLength = 2; |
| 2084 | static const int kEnumCacheBridgeEnumIndex = 0; |
| 2085 | static const int kEnumCacheBridgeCacheIndex = 1; |
| 2086 | |
| 2087 | // Layout description. |
| 2088 | static const int kContentArrayOffset = FixedArray::kHeaderSize; |
| 2089 | static const int kEnumerationIndexOffset = kContentArrayOffset + kPointerSize; |
| 2090 | static const int kFirstOffset = kEnumerationIndexOffset + kPointerSize; |
| 2091 | |
| 2092 | // Layout description for the bridge array. |
| 2093 | static const int kEnumCacheBridgeEnumOffset = FixedArray::kHeaderSize; |
| 2094 | static const int kEnumCacheBridgeCacheOffset = |
| 2095 | kEnumCacheBridgeEnumOffset + kPointerSize; |
| 2096 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2097 | #ifdef OBJECT_PRINT |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2098 | // Print all the descriptors. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2099 | inline void PrintDescriptors() { |
| 2100 | PrintDescriptors(stdout); |
| 2101 | } |
| 2102 | void PrintDescriptors(FILE* out); |
| 2103 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2104 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2105 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2106 | // Is the descriptor array sorted and without duplicates? |
| 2107 | bool IsSortedNoDuplicates(); |
| 2108 | |
| 2109 | // Are two DescriptorArrays equal? |
| 2110 | bool IsEqualTo(DescriptorArray* other); |
| 2111 | #endif |
| 2112 | |
| 2113 | // The maximum number of descriptors we want in a descriptor array (should |
| 2114 | // fit in a page). |
| 2115 | static const int kMaxNumberOfDescriptors = 1024 + 512; |
| 2116 | |
| 2117 | private: |
| 2118 | // Conversion from descriptor number to array indices. |
| 2119 | static int ToKeyIndex(int descriptor_number) { |
| 2120 | return descriptor_number+kFirstIndex; |
| 2121 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2122 | |
| 2123 | static int ToDetailsIndex(int descriptor_number) { |
| 2124 | return (descriptor_number << 1) + 1; |
| 2125 | } |
| 2126 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2127 | static int ToValueIndex(int descriptor_number) { |
| 2128 | return descriptor_number << 1; |
| 2129 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2130 | |
| 2131 | bool is_null_descriptor(int descriptor_number) { |
| 2132 | return PropertyDetails(GetDetails(descriptor_number)).type() == |
| 2133 | NULL_DESCRIPTOR; |
| 2134 | } |
| 2135 | // Swap operation on FixedArray without using write barriers. |
| 2136 | static inline void fast_swap(FixedArray* array, int first, int second); |
| 2137 | |
| 2138 | // Swap descriptor first and second. |
| 2139 | inline void Swap(int first, int second); |
| 2140 | |
| 2141 | FixedArray* GetContentArray() { |
| 2142 | return FixedArray::cast(get(kContentArrayIndex)); |
| 2143 | } |
| 2144 | DISALLOW_IMPLICIT_CONSTRUCTORS(DescriptorArray); |
| 2145 | }; |
| 2146 | |
| 2147 | |
| 2148 | // HashTable is a subclass of FixedArray that implements a hash table |
| 2149 | // that uses open addressing and quadratic probing. |
| 2150 | // |
| 2151 | // In order for the quadratic probing to work, elements that have not |
| 2152 | // yet been used and elements that have been deleted are |
| 2153 | // distinguished. Probing continues when deleted elements are |
| 2154 | // encountered and stops when unused elements are encountered. |
| 2155 | // |
| 2156 | // - Elements with key == undefined have not been used yet. |
| 2157 | // - Elements with key == null have been deleted. |
| 2158 | // |
| 2159 | // The hash table class is parameterized with a Shape and a Key. |
| 2160 | // Shape must be a class with the following interface: |
| 2161 | // class ExampleShape { |
| 2162 | // public: |
| 2163 | // // Tells whether key matches other. |
| 2164 | // static bool IsMatch(Key key, Object* other); |
| 2165 | // // Returns the hash value for key. |
| 2166 | // static uint32_t Hash(Key key); |
| 2167 | // // Returns the hash value for object. |
| 2168 | // static uint32_t HashForObject(Key key, Object* object); |
| 2169 | // // Convert key to an object. |
| 2170 | // static inline Object* AsObject(Key key); |
| 2171 | // // The prefix size indicates number of elements in the beginning |
| 2172 | // // of the backing storage. |
| 2173 | // static const int kPrefixSize = ..; |
| 2174 | // // The Element size indicates number of elements per entry. |
| 2175 | // static const int kEntrySize = ..; |
| 2176 | // }; |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2177 | // The prefix size indicates an amount of memory in the |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2178 | // beginning of the backing storage that can be used for non-element |
| 2179 | // information by subclasses. |
| 2180 | |
| 2181 | template<typename Shape, typename Key> |
| 2182 | class HashTable: public FixedArray { |
| 2183 | public: |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2184 | // Returns the number of elements in the hash table. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2185 | int NumberOfElements() { |
| 2186 | return Smi::cast(get(kNumberOfElementsIndex))->value(); |
| 2187 | } |
| 2188 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2189 | // Returns the number of deleted elements in the hash table. |
| 2190 | int NumberOfDeletedElements() { |
| 2191 | return Smi::cast(get(kNumberOfDeletedElementsIndex))->value(); |
| 2192 | } |
| 2193 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2194 | // Returns the capacity of the hash table. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2195 | int Capacity() { |
| 2196 | return Smi::cast(get(kCapacityIndex))->value(); |
| 2197 | } |
| 2198 | |
| 2199 | // ElementAdded should be called whenever an element is added to a |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2200 | // hash table. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2201 | void ElementAdded() { SetNumberOfElements(NumberOfElements() + 1); } |
| 2202 | |
| 2203 | // ElementRemoved should be called whenever an element is removed from |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2204 | // a hash table. |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2205 | void ElementRemoved() { |
| 2206 | SetNumberOfElements(NumberOfElements() - 1); |
| 2207 | SetNumberOfDeletedElements(NumberOfDeletedElements() + 1); |
| 2208 | } |
| 2209 | void ElementsRemoved(int n) { |
| 2210 | SetNumberOfElements(NumberOfElements() - n); |
| 2211 | SetNumberOfDeletedElements(NumberOfDeletedElements() + n); |
| 2212 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2213 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2214 | // Returns a new HashTable object. Might return Failure. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2215 | MUST_USE_RESULT static MaybeObject* Allocate( |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2216 | int at_least_space_for, |
| 2217 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2218 | |
| 2219 | // Returns the key at entry. |
| 2220 | Object* KeyAt(int entry) { return get(EntryToIndex(entry)); } |
| 2221 | |
| 2222 | // Tells whether k is a real key. Null and undefined are not allowed |
| 2223 | // as keys and can be used to indicate missing or deleted elements. |
| 2224 | bool IsKey(Object* k) { |
| 2225 | return !k->IsNull() && !k->IsUndefined(); |
| 2226 | } |
| 2227 | |
| 2228 | // Garbage collection support. |
| 2229 | void IteratePrefix(ObjectVisitor* visitor); |
| 2230 | void IterateElements(ObjectVisitor* visitor); |
| 2231 | |
| 2232 | // Casting. |
| 2233 | static inline HashTable* cast(Object* obj); |
| 2234 | |
| 2235 | // Compute the probe offset (quadratic probing). |
| 2236 | INLINE(static uint32_t GetProbeOffset(uint32_t n)) { |
| 2237 | return (n + n * n) >> 1; |
| 2238 | } |
| 2239 | |
| 2240 | static const int kNumberOfElementsIndex = 0; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2241 | static const int kNumberOfDeletedElementsIndex = 1; |
| 2242 | static const int kCapacityIndex = 2; |
| 2243 | static const int kPrefixStartIndex = 3; |
| 2244 | static const int kElementsStartIndex = |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2245 | kPrefixStartIndex + Shape::kPrefixSize; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2246 | static const int kEntrySize = Shape::kEntrySize; |
| 2247 | static const int kElementsStartOffset = |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2248 | kHeaderSize + kElementsStartIndex * kPointerSize; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2249 | static const int kCapacityOffset = |
| 2250 | kHeaderSize + kCapacityIndex * kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2251 | |
| 2252 | // Constant used for denoting a absent entry. |
| 2253 | static const int kNotFound = -1; |
| 2254 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2255 | // Maximal capacity of HashTable. Based on maximal length of underlying |
| 2256 | // FixedArray. Staying below kMaxCapacity also ensures that EntryToIndex |
| 2257 | // cannot overflow. |
| 2258 | static const int kMaxCapacity = |
| 2259 | (FixedArray::kMaxLength - kElementsStartOffset) / kEntrySize; |
| 2260 | |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 2261 | // Find entry for key otherwise return kNotFound. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2262 | int FindEntry(Key key); |
| 2263 | |
| 2264 | protected: |
| 2265 | |
| 2266 | // Find the entry at which to insert element with the given key that |
| 2267 | // has the given hash value. |
| 2268 | uint32_t FindInsertionEntry(uint32_t hash); |
| 2269 | |
| 2270 | // Returns the index for an entry (of the key) |
| 2271 | static inline int EntryToIndex(int entry) { |
| 2272 | return (entry * kEntrySize) + kElementsStartIndex; |
| 2273 | } |
| 2274 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2275 | // Update the number of elements in the hash table. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2276 | void SetNumberOfElements(int nof) { |
| 2277 | fast_set(this, kNumberOfElementsIndex, Smi::FromInt(nof)); |
| 2278 | } |
| 2279 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2280 | // Update the number of deleted elements in the hash table. |
| 2281 | void SetNumberOfDeletedElements(int nod) { |
| 2282 | fast_set(this, kNumberOfDeletedElementsIndex, Smi::FromInt(nod)); |
| 2283 | } |
| 2284 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2285 | // Sets the capacity of the hash table. |
| 2286 | void SetCapacity(int capacity) { |
| 2287 | // To scale a computed hash code to fit within the hash table, we |
| 2288 | // use bit-wise AND with a mask, so the capacity must be positive |
| 2289 | // and non-zero. |
| 2290 | ASSERT(capacity > 0); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2291 | ASSERT(capacity <= kMaxCapacity); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2292 | fast_set(this, kCapacityIndex, Smi::FromInt(capacity)); |
| 2293 | } |
| 2294 | |
| 2295 | |
| 2296 | // Returns probe entry. |
| 2297 | static uint32_t GetProbe(uint32_t hash, uint32_t number, uint32_t size) { |
| 2298 | ASSERT(IsPowerOf2(size)); |
| 2299 | return (hash + GetProbeOffset(number)) & (size - 1); |
| 2300 | } |
| 2301 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2302 | static uint32_t FirstProbe(uint32_t hash, uint32_t size) { |
| 2303 | return hash & (size - 1); |
| 2304 | } |
| 2305 | |
| 2306 | static uint32_t NextProbe(uint32_t last, uint32_t number, uint32_t size) { |
| 2307 | return (last + number) & (size - 1); |
| 2308 | } |
| 2309 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2310 | // Ensure enough space for n additional elements. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2311 | MUST_USE_RESULT MaybeObject* EnsureCapacity(int n, Key key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2312 | }; |
| 2313 | |
| 2314 | |
| 2315 | |
| 2316 | // HashTableKey is an abstract superclass for virtual key behavior. |
| 2317 | class HashTableKey { |
| 2318 | public: |
| 2319 | // Returns whether the other object matches this key. |
| 2320 | virtual bool IsMatch(Object* other) = 0; |
| 2321 | // Returns the hash value for this key. |
| 2322 | virtual uint32_t Hash() = 0; |
| 2323 | // Returns the hash value for object. |
| 2324 | virtual uint32_t HashForObject(Object* key) = 0; |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2325 | // Returns the key object for storing into the hash table. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2326 | // If allocations fails a failure object is returned. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2327 | MUST_USE_RESULT virtual MaybeObject* AsObject() = 0; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2328 | // Required. |
| 2329 | virtual ~HashTableKey() {} |
| 2330 | }; |
| 2331 | |
| 2332 | class SymbolTableShape { |
| 2333 | public: |
| 2334 | static bool IsMatch(HashTableKey* key, Object* value) { |
| 2335 | return key->IsMatch(value); |
| 2336 | } |
| 2337 | static uint32_t Hash(HashTableKey* key) { |
| 2338 | return key->Hash(); |
| 2339 | } |
| 2340 | static uint32_t HashForObject(HashTableKey* key, Object* object) { |
| 2341 | return key->HashForObject(object); |
| 2342 | } |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2343 | MUST_USE_RESULT static MaybeObject* AsObject(HashTableKey* key) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2344 | return key->AsObject(); |
| 2345 | } |
| 2346 | |
| 2347 | static const int kPrefixSize = 0; |
| 2348 | static const int kEntrySize = 1; |
| 2349 | }; |
| 2350 | |
| 2351 | // SymbolTable. |
| 2352 | // |
| 2353 | // No special elements in the prefix and the element size is 1 |
| 2354 | // because only the symbol itself (the key) needs to be stored. |
| 2355 | class SymbolTable: public HashTable<SymbolTableShape, HashTableKey*> { |
| 2356 | public: |
| 2357 | // Find symbol in the symbol table. If it is not there yet, it is |
| 2358 | // added. The return value is the symbol table which might have |
| 2359 | // been enlarged. If the return value is not a failure, the symbol |
| 2360 | // pointer *s is set to the symbol found. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2361 | MUST_USE_RESULT MaybeObject* LookupSymbol(Vector<const char> str, Object** s); |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 2362 | MUST_USE_RESULT MaybeObject* LookupAsciiSymbol(Vector<const char> str, |
| 2363 | Object** s); |
| 2364 | MUST_USE_RESULT MaybeObject* LookupTwoByteSymbol(Vector<const uc16> str, |
| 2365 | Object** s); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2366 | MUST_USE_RESULT MaybeObject* LookupString(String* key, Object** s); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2367 | |
| 2368 | // Looks up a symbol that is equal to the given string and returns |
| 2369 | // true if it is found, assigning the symbol to the given output |
| 2370 | // parameter. |
| 2371 | bool LookupSymbolIfExists(String* str, String** symbol); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2372 | bool LookupTwoCharsSymbolIfExists(uint32_t c1, uint32_t c2, String** symbol); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2373 | |
| 2374 | // Casting. |
| 2375 | static inline SymbolTable* cast(Object* obj); |
| 2376 | |
| 2377 | private: |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2378 | MUST_USE_RESULT MaybeObject* LookupKey(HashTableKey* key, Object** s); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2379 | |
| 2380 | DISALLOW_IMPLICIT_CONSTRUCTORS(SymbolTable); |
| 2381 | }; |
| 2382 | |
| 2383 | |
| 2384 | class MapCacheShape { |
| 2385 | public: |
| 2386 | static bool IsMatch(HashTableKey* key, Object* value) { |
| 2387 | return key->IsMatch(value); |
| 2388 | } |
| 2389 | static uint32_t Hash(HashTableKey* key) { |
| 2390 | return key->Hash(); |
| 2391 | } |
| 2392 | |
| 2393 | static uint32_t HashForObject(HashTableKey* key, Object* object) { |
| 2394 | return key->HashForObject(object); |
| 2395 | } |
| 2396 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2397 | MUST_USE_RESULT static MaybeObject* AsObject(HashTableKey* key) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2398 | return key->AsObject(); |
| 2399 | } |
| 2400 | |
| 2401 | static const int kPrefixSize = 0; |
| 2402 | static const int kEntrySize = 2; |
| 2403 | }; |
| 2404 | |
| 2405 | |
| 2406 | // MapCache. |
| 2407 | // |
| 2408 | // Maps keys that are a fixed array of symbols to a map. |
| 2409 | // Used for canonicalize maps for object literals. |
| 2410 | class MapCache: public HashTable<MapCacheShape, HashTableKey*> { |
| 2411 | public: |
| 2412 | // Find cached value for a string key, otherwise return null. |
| 2413 | Object* Lookup(FixedArray* key); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2414 | MUST_USE_RESULT MaybeObject* Put(FixedArray* key, Map* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2415 | static inline MapCache* cast(Object* obj); |
| 2416 | |
| 2417 | private: |
| 2418 | DISALLOW_IMPLICIT_CONSTRUCTORS(MapCache); |
| 2419 | }; |
| 2420 | |
| 2421 | |
| 2422 | template <typename Shape, typename Key> |
| 2423 | class Dictionary: public HashTable<Shape, Key> { |
| 2424 | public: |
| 2425 | |
| 2426 | static inline Dictionary<Shape, Key>* cast(Object* obj) { |
| 2427 | return reinterpret_cast<Dictionary<Shape, Key>*>(obj); |
| 2428 | } |
| 2429 | |
| 2430 | // Returns the value at entry. |
| 2431 | Object* ValueAt(int entry) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2432 | return this->get(HashTable<Shape, Key>::EntryToIndex(entry)+1); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2433 | } |
| 2434 | |
| 2435 | // Set the value for entry. |
| 2436 | void ValueAtPut(int entry, Object* value) { |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 2437 | // Check that this value can actually be written. |
| 2438 | PropertyDetails details = DetailsAt(entry); |
| 2439 | // If a value has not been initilized we allow writing to it even if |
| 2440 | // it is read only (a declared const that has not been initialized). |
| 2441 | if (details.IsReadOnly() && !ValueAt(entry)->IsTheHole()) return; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2442 | this->set(HashTable<Shape, Key>::EntryToIndex(entry)+1, value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2443 | } |
| 2444 | |
| 2445 | // Returns the property details for the property at entry. |
| 2446 | PropertyDetails DetailsAt(int entry) { |
| 2447 | ASSERT(entry >= 0); // Not found is -1, which is not caught by get(). |
| 2448 | return PropertyDetails( |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2449 | Smi::cast(this->get(HashTable<Shape, Key>::EntryToIndex(entry) + 2))); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2450 | } |
| 2451 | |
| 2452 | // Set the details for entry. |
| 2453 | void DetailsAtPut(int entry, PropertyDetails value) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2454 | this->set(HashTable<Shape, Key>::EntryToIndex(entry) + 2, value.AsSmi()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2455 | } |
| 2456 | |
| 2457 | // Sorting support |
| 2458 | void CopyValuesTo(FixedArray* elements); |
| 2459 | |
| 2460 | // Delete a property from the dictionary. |
| 2461 | Object* DeleteProperty(int entry, JSObject::DeleteMode mode); |
| 2462 | |
| 2463 | // Returns the number of elements in the dictionary filtering out properties |
| 2464 | // with the specified attributes. |
| 2465 | int NumberOfElementsFilterAttributes(PropertyAttributes filter); |
| 2466 | |
| 2467 | // Returns the number of enumerable elements in the dictionary. |
| 2468 | int NumberOfEnumElements(); |
| 2469 | |
| 2470 | // Copies keys to preallocated fixed array. |
| 2471 | void CopyKeysTo(FixedArray* storage, PropertyAttributes filter); |
| 2472 | // Fill in details for properties into storage. |
| 2473 | void CopyKeysTo(FixedArray* storage); |
| 2474 | |
| 2475 | // Accessors for next enumeration index. |
| 2476 | void SetNextEnumerationIndex(int index) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2477 | this->fast_set(this, kNextEnumerationIndexIndex, Smi::FromInt(index)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2478 | } |
| 2479 | |
| 2480 | int NextEnumerationIndex() { |
| 2481 | return Smi::cast(FixedArray::get(kNextEnumerationIndexIndex))->value(); |
| 2482 | } |
| 2483 | |
| 2484 | // Returns a new array for dictionary usage. Might return Failure. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2485 | MUST_USE_RESULT static MaybeObject* Allocate(int at_least_space_for); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2486 | |
| 2487 | // Ensure enough space for n additional elements. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2488 | MUST_USE_RESULT MaybeObject* EnsureCapacity(int n, Key key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2489 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2490 | #ifdef OBJECT_PRINT |
| 2491 | inline void Print() { |
| 2492 | Print(stdout); |
| 2493 | } |
| 2494 | void Print(FILE* out); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2495 | #endif |
| 2496 | // Returns the key (slow). |
| 2497 | Object* SlowReverseLookup(Object* value); |
| 2498 | |
| 2499 | // Sets the entry to (key, value) pair. |
| 2500 | inline void SetEntry(int entry, |
| 2501 | Object* key, |
| 2502 | Object* value, |
| 2503 | PropertyDetails details); |
| 2504 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2505 | MUST_USE_RESULT MaybeObject* Add(Key key, |
| 2506 | Object* value, |
| 2507 | PropertyDetails details); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2508 | |
| 2509 | protected: |
| 2510 | // Generic at put operation. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2511 | MUST_USE_RESULT MaybeObject* AtPut(Key key, Object* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2512 | |
| 2513 | // Add entry to dictionary. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2514 | MUST_USE_RESULT MaybeObject* AddEntry(Key key, |
| 2515 | Object* value, |
| 2516 | PropertyDetails details, |
| 2517 | uint32_t hash); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2518 | |
| 2519 | // Generate new enumeration indices to avoid enumeration index overflow. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2520 | MUST_USE_RESULT MaybeObject* GenerateNewEnumerationIndices(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2521 | static const int kMaxNumberKeyIndex = |
| 2522 | HashTable<Shape, Key>::kPrefixStartIndex; |
| 2523 | static const int kNextEnumerationIndexIndex = kMaxNumberKeyIndex + 1; |
| 2524 | }; |
| 2525 | |
| 2526 | |
| 2527 | class StringDictionaryShape { |
| 2528 | public: |
| 2529 | static inline bool IsMatch(String* key, Object* other); |
| 2530 | static inline uint32_t Hash(String* key); |
| 2531 | static inline uint32_t HashForObject(String* key, Object* object); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2532 | MUST_USE_RESULT static inline MaybeObject* AsObject(String* key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2533 | static const int kPrefixSize = 2; |
| 2534 | static const int kEntrySize = 3; |
| 2535 | static const bool kIsEnumerable = true; |
| 2536 | }; |
| 2537 | |
| 2538 | |
| 2539 | class StringDictionary: public Dictionary<StringDictionaryShape, String*> { |
| 2540 | public: |
| 2541 | static inline StringDictionary* cast(Object* obj) { |
| 2542 | ASSERT(obj->IsDictionary()); |
| 2543 | return reinterpret_cast<StringDictionary*>(obj); |
| 2544 | } |
| 2545 | |
| 2546 | // Copies enumerable keys to preallocated fixed array. |
| 2547 | void CopyEnumKeysTo(FixedArray* storage, FixedArray* sort_array); |
| 2548 | |
| 2549 | // For transforming properties of a JSObject. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2550 | MUST_USE_RESULT MaybeObject* TransformPropertiesToFastFor( |
| 2551 | JSObject* obj, |
| 2552 | int unused_property_fields); |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 2553 | |
| 2554 | // Find entry for key otherwise return kNotFound. Optimzed version of |
| 2555 | // HashTable::FindEntry. |
| 2556 | int FindEntry(String* key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2557 | }; |
| 2558 | |
| 2559 | |
| 2560 | class NumberDictionaryShape { |
| 2561 | public: |
| 2562 | static inline bool IsMatch(uint32_t key, Object* other); |
| 2563 | static inline uint32_t Hash(uint32_t key); |
| 2564 | static inline uint32_t HashForObject(uint32_t key, Object* object); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2565 | MUST_USE_RESULT static inline MaybeObject* AsObject(uint32_t key); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2566 | static const int kPrefixSize = 2; |
| 2567 | static const int kEntrySize = 3; |
| 2568 | static const bool kIsEnumerable = false; |
| 2569 | }; |
| 2570 | |
| 2571 | |
| 2572 | class NumberDictionary: public Dictionary<NumberDictionaryShape, uint32_t> { |
| 2573 | public: |
| 2574 | static NumberDictionary* cast(Object* obj) { |
| 2575 | ASSERT(obj->IsDictionary()); |
| 2576 | return reinterpret_cast<NumberDictionary*>(obj); |
| 2577 | } |
| 2578 | |
| 2579 | // Type specific at put (default NONE attributes is used when adding). |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2580 | MUST_USE_RESULT MaybeObject* AtNumberPut(uint32_t key, Object* value); |
| 2581 | MUST_USE_RESULT MaybeObject* AddNumberEntry(uint32_t key, |
| 2582 | Object* value, |
| 2583 | PropertyDetails details); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2584 | |
| 2585 | // Set an existing entry or add a new one if needed. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2586 | MUST_USE_RESULT MaybeObject* Set(uint32_t key, |
| 2587 | Object* value, |
| 2588 | PropertyDetails details); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2589 | |
| 2590 | void UpdateMaxNumberKey(uint32_t key); |
| 2591 | |
| 2592 | // If slow elements are required we will never go back to fast-case |
| 2593 | // for the elements kept in this dictionary. We require slow |
| 2594 | // elements if an element has been added at an index larger than |
| 2595 | // kRequiresSlowElementsLimit or set_requires_slow_elements() has been called |
| 2596 | // when defining a getter or setter with a number key. |
| 2597 | inline bool requires_slow_elements(); |
| 2598 | inline void set_requires_slow_elements(); |
| 2599 | |
| 2600 | // Get the value of the max number key that has been added to this |
| 2601 | // dictionary. max_number_key can only be called if |
| 2602 | // requires_slow_elements returns false. |
| 2603 | inline uint32_t max_number_key(); |
| 2604 | |
| 2605 | // Remove all entries were key is a number and (from <= key && key < to). |
| 2606 | void RemoveNumberEntries(uint32_t from, uint32_t to); |
| 2607 | |
| 2608 | // Bit masks. |
| 2609 | static const int kRequiresSlowElementsMask = 1; |
| 2610 | static const int kRequiresSlowElementsTagSize = 1; |
| 2611 | static const uint32_t kRequiresSlowElementsLimit = (1 << 29) - 1; |
| 2612 | }; |
| 2613 | |
| 2614 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2615 | // JSFunctionResultCache caches results of some JSFunction invocation. |
| 2616 | // It is a fixed array with fixed structure: |
| 2617 | // [0]: factory function |
| 2618 | // [1]: finger index |
| 2619 | // [2]: current cache size |
| 2620 | // [3]: dummy field. |
| 2621 | // The rest of array are key/value pairs. |
| 2622 | class JSFunctionResultCache: public FixedArray { |
| 2623 | public: |
| 2624 | static const int kFactoryIndex = 0; |
| 2625 | static const int kFingerIndex = kFactoryIndex + 1; |
| 2626 | static const int kCacheSizeIndex = kFingerIndex + 1; |
| 2627 | static const int kDummyIndex = kCacheSizeIndex + 1; |
| 2628 | static const int kEntriesIndex = kDummyIndex + 1; |
| 2629 | |
| 2630 | static const int kEntrySize = 2; // key + value |
| 2631 | |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 2632 | static const int kFactoryOffset = kHeaderSize; |
| 2633 | static const int kFingerOffset = kFactoryOffset + kPointerSize; |
| 2634 | static const int kCacheSizeOffset = kFingerOffset + kPointerSize; |
| 2635 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2636 | inline void MakeZeroSize(); |
| 2637 | inline void Clear(); |
| 2638 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 2639 | inline int size(); |
| 2640 | inline void set_size(int size); |
| 2641 | inline int finger_index(); |
| 2642 | inline void set_finger_index(int finger_index); |
| 2643 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2644 | // Casting |
| 2645 | static inline JSFunctionResultCache* cast(Object* obj); |
| 2646 | |
| 2647 | #ifdef DEBUG |
| 2648 | void JSFunctionResultCacheVerify(); |
| 2649 | #endif |
| 2650 | }; |
| 2651 | |
| 2652 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2653 | // The cache for maps used by normalized (dictionary mode) objects. |
| 2654 | // Such maps do not have property descriptors, so a typical program |
| 2655 | // needs very limited number of distinct normalized maps. |
| 2656 | class NormalizedMapCache: public FixedArray { |
| 2657 | public: |
| 2658 | static const int kEntries = 64; |
| 2659 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2660 | MUST_USE_RESULT MaybeObject* Get(JSObject* object, |
| 2661 | PropertyNormalizationMode mode); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2662 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2663 | void Clear(); |
| 2664 | |
| 2665 | // Casting |
| 2666 | static inline NormalizedMapCache* cast(Object* obj); |
| 2667 | |
| 2668 | #ifdef DEBUG |
| 2669 | void NormalizedMapCacheVerify(); |
| 2670 | #endif |
| 2671 | |
| 2672 | private: |
| 2673 | static int Hash(Map* fast); |
| 2674 | |
| 2675 | static bool CheckHit(Map* slow, Map* fast, PropertyNormalizationMode mode); |
| 2676 | }; |
| 2677 | |
| 2678 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2679 | // ByteArray represents fixed sized byte arrays. Used by the outside world, |
| 2680 | // such as PCRE, and also by the memory allocator and garbage collector to |
| 2681 | // fill in free blocks in the heap. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2682 | class ByteArray: public HeapObject { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2683 | public: |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2684 | // [length]: length of the array. |
| 2685 | inline int length(); |
| 2686 | inline void set_length(int value); |
| 2687 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2688 | // Setter and getter. |
| 2689 | inline byte get(int index); |
| 2690 | inline void set(int index, byte value); |
| 2691 | |
| 2692 | // Treat contents as an int array. |
| 2693 | inline int get_int(int index); |
| 2694 | |
| 2695 | static int SizeFor(int length) { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2696 | return OBJECT_POINTER_ALIGN(kHeaderSize + length); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2697 | } |
| 2698 | // We use byte arrays for free blocks in the heap. Given a desired size in |
| 2699 | // bytes that is a multiple of the word size and big enough to hold a byte |
| 2700 | // array, this function returns the number of elements a byte array should |
| 2701 | // have. |
| 2702 | static int LengthFor(int size_in_bytes) { |
| 2703 | ASSERT(IsAligned(size_in_bytes, kPointerSize)); |
| 2704 | ASSERT(size_in_bytes >= kHeaderSize); |
| 2705 | return size_in_bytes - kHeaderSize; |
| 2706 | } |
| 2707 | |
| 2708 | // Returns data start address. |
| 2709 | inline Address GetDataStartAddress(); |
| 2710 | |
| 2711 | // Returns a pointer to the ByteArray object for a given data start address. |
| 2712 | static inline ByteArray* FromDataStartAddress(Address address); |
| 2713 | |
| 2714 | // Casting. |
| 2715 | static inline ByteArray* cast(Object* obj); |
| 2716 | |
| 2717 | // Dispatched behavior. |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 2718 | inline int ByteArraySize() { |
| 2719 | return SizeFor(this->length()); |
| 2720 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2721 | #ifdef OBJECT_PRINT |
| 2722 | inline void ByteArrayPrint() { |
| 2723 | ByteArrayPrint(stdout); |
| 2724 | } |
| 2725 | void ByteArrayPrint(FILE* out); |
| 2726 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2727 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2728 | void ByteArrayVerify(); |
| 2729 | #endif |
| 2730 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2731 | // Layout description. |
| 2732 | // Length is smi tagged when it is stored. |
| 2733 | static const int kLengthOffset = HeapObject::kHeaderSize; |
| 2734 | static const int kHeaderSize = kLengthOffset + kPointerSize; |
| 2735 | |
| 2736 | static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2737 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2738 | // Maximal memory consumption for a single ByteArray. |
| 2739 | static const int kMaxSize = 512 * MB; |
| 2740 | // Maximal length of a single ByteArray. |
| 2741 | static const int kMaxLength = kMaxSize - kHeaderSize; |
| 2742 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2743 | private: |
| 2744 | DISALLOW_IMPLICIT_CONSTRUCTORS(ByteArray); |
| 2745 | }; |
| 2746 | |
| 2747 | |
| 2748 | // A PixelArray represents a fixed-size byte array with special semantics |
| 2749 | // used for implementing the CanvasPixelArray object. Please see the |
| 2750 | // specification at: |
| 2751 | // http://www.whatwg.org/specs/web-apps/current-work/ |
| 2752 | // multipage/the-canvas-element.html#canvaspixelarray |
| 2753 | // In particular, write access clamps the value written to 0 or 255 if the |
| 2754 | // value written is outside this range. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2755 | class PixelArray: public HeapObject { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2756 | public: |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2757 | // [length]: length of the array. |
| 2758 | inline int length(); |
| 2759 | inline void set_length(int value); |
| 2760 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2761 | // [external_pointer]: The pointer to the external memory area backing this |
| 2762 | // pixel array. |
| 2763 | DECL_ACCESSORS(external_pointer, uint8_t) // Pointer to the data store. |
| 2764 | |
| 2765 | // Setter and getter. |
| 2766 | inline uint8_t get(int index); |
| 2767 | inline void set(int index, uint8_t value); |
| 2768 | |
| 2769 | // This accessor applies the correct conversion from Smi, HeapNumber and |
| 2770 | // undefined and clamps the converted value between 0 and 255. |
| 2771 | Object* SetValue(uint32_t index, Object* value); |
| 2772 | |
| 2773 | // Casting. |
| 2774 | static inline PixelArray* cast(Object* obj); |
| 2775 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2776 | #ifdef OBJECT_PRINT |
| 2777 | inline void PixelArrayPrint() { |
| 2778 | PixelArrayPrint(stdout); |
| 2779 | } |
| 2780 | void PixelArrayPrint(FILE* out); |
| 2781 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2782 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2783 | void PixelArrayVerify(); |
| 2784 | #endif // DEBUG |
| 2785 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2786 | // Maximal acceptable length for a pixel array. |
| 2787 | static const int kMaxLength = 0x3fffffff; |
| 2788 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2789 | // PixelArray headers are not quadword aligned. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2790 | static const int kLengthOffset = HeapObject::kHeaderSize; |
| 2791 | static const int kExternalPointerOffset = |
| 2792 | POINTER_SIZE_ALIGN(kLengthOffset + kIntSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2793 | static const int kHeaderSize = kExternalPointerOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2794 | static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2795 | |
| 2796 | private: |
| 2797 | DISALLOW_IMPLICIT_CONSTRUCTORS(PixelArray); |
| 2798 | }; |
| 2799 | |
| 2800 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2801 | // An ExternalArray represents a fixed-size array of primitive values |
| 2802 | // which live outside the JavaScript heap. Its subclasses are used to |
| 2803 | // implement the CanvasArray types being defined in the WebGL |
| 2804 | // specification. As of this writing the first public draft is not yet |
| 2805 | // available, but Khronos members can access the draft at: |
| 2806 | // https://cvs.khronos.org/svn/repos/3dweb/trunk/doc/spec/WebGL-spec.html |
| 2807 | // |
| 2808 | // The semantics of these arrays differ from CanvasPixelArray. |
| 2809 | // Out-of-range values passed to the setter are converted via a C |
| 2810 | // cast, not clamping. Out-of-range indices cause exceptions to be |
| 2811 | // raised rather than being silently ignored. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2812 | class ExternalArray: public HeapObject { |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2813 | public: |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2814 | // [length]: length of the array. |
| 2815 | inline int length(); |
| 2816 | inline void set_length(int value); |
| 2817 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2818 | // [external_pointer]: The pointer to the external memory area backing this |
| 2819 | // external array. |
| 2820 | DECL_ACCESSORS(external_pointer, void) // Pointer to the data store. |
| 2821 | |
| 2822 | // Casting. |
| 2823 | static inline ExternalArray* cast(Object* obj); |
| 2824 | |
| 2825 | // Maximal acceptable length for an external array. |
| 2826 | static const int kMaxLength = 0x3fffffff; |
| 2827 | |
| 2828 | // ExternalArray headers are not quadword aligned. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2829 | static const int kLengthOffset = HeapObject::kHeaderSize; |
| 2830 | static const int kExternalPointerOffset = |
| 2831 | POINTER_SIZE_ALIGN(kLengthOffset + kIntSize); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2832 | static const int kHeaderSize = kExternalPointerOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2833 | static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2834 | |
| 2835 | private: |
| 2836 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalArray); |
| 2837 | }; |
| 2838 | |
| 2839 | |
| 2840 | class ExternalByteArray: public ExternalArray { |
| 2841 | public: |
| 2842 | // Setter and getter. |
| 2843 | inline int8_t get(int index); |
| 2844 | inline void set(int index, int8_t value); |
| 2845 | |
| 2846 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 2847 | // and undefined. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2848 | MaybeObject* SetValue(uint32_t index, Object* value); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2849 | |
| 2850 | // Casting. |
| 2851 | static inline ExternalByteArray* cast(Object* obj); |
| 2852 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2853 | #ifdef OBJECT_PRINT |
| 2854 | inline void ExternalByteArrayPrint() { |
| 2855 | ExternalByteArrayPrint(stdout); |
| 2856 | } |
| 2857 | void ExternalByteArrayPrint(FILE* out); |
| 2858 | #endif |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2859 | #ifdef DEBUG |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2860 | void ExternalByteArrayVerify(); |
| 2861 | #endif // DEBUG |
| 2862 | |
| 2863 | private: |
| 2864 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalByteArray); |
| 2865 | }; |
| 2866 | |
| 2867 | |
| 2868 | class ExternalUnsignedByteArray: public ExternalArray { |
| 2869 | public: |
| 2870 | // Setter and getter. |
| 2871 | inline uint8_t get(int index); |
| 2872 | inline void set(int index, uint8_t value); |
| 2873 | |
| 2874 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 2875 | // and undefined. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2876 | MaybeObject* SetValue(uint32_t index, Object* value); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2877 | |
| 2878 | // Casting. |
| 2879 | static inline ExternalUnsignedByteArray* cast(Object* obj); |
| 2880 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2881 | #ifdef OBJECT_PRINT |
| 2882 | inline void ExternalUnsignedByteArrayPrint() { |
| 2883 | ExternalUnsignedByteArrayPrint(stdout); |
| 2884 | } |
| 2885 | void ExternalUnsignedByteArrayPrint(FILE* out); |
| 2886 | #endif |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2887 | #ifdef DEBUG |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2888 | void ExternalUnsignedByteArrayVerify(); |
| 2889 | #endif // DEBUG |
| 2890 | |
| 2891 | private: |
| 2892 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedByteArray); |
| 2893 | }; |
| 2894 | |
| 2895 | |
| 2896 | class ExternalShortArray: public ExternalArray { |
| 2897 | public: |
| 2898 | // Setter and getter. |
| 2899 | inline int16_t get(int index); |
| 2900 | inline void set(int index, int16_t value); |
| 2901 | |
| 2902 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 2903 | // and undefined. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2904 | MaybeObject* SetValue(uint32_t index, Object* value); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2905 | |
| 2906 | // Casting. |
| 2907 | static inline ExternalShortArray* cast(Object* obj); |
| 2908 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2909 | #ifdef OBJECT_PRINT |
| 2910 | inline void ExternalShortArrayPrint() { |
| 2911 | ExternalShortArrayPrint(stdout); |
| 2912 | } |
| 2913 | void ExternalShortArrayPrint(FILE* out); |
| 2914 | #endif |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2915 | #ifdef DEBUG |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2916 | void ExternalShortArrayVerify(); |
| 2917 | #endif // DEBUG |
| 2918 | |
| 2919 | private: |
| 2920 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalShortArray); |
| 2921 | }; |
| 2922 | |
| 2923 | |
| 2924 | class ExternalUnsignedShortArray: public ExternalArray { |
| 2925 | public: |
| 2926 | // Setter and getter. |
| 2927 | inline uint16_t get(int index); |
| 2928 | inline void set(int index, uint16_t value); |
| 2929 | |
| 2930 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 2931 | // and undefined. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2932 | MaybeObject* SetValue(uint32_t index, Object* value); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2933 | |
| 2934 | // Casting. |
| 2935 | static inline ExternalUnsignedShortArray* cast(Object* obj); |
| 2936 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2937 | #ifdef OBJECT_PRINT |
| 2938 | inline void ExternalUnsignedShortArrayPrint() { |
| 2939 | ExternalUnsignedShortArrayPrint(stdout); |
| 2940 | } |
| 2941 | void ExternalUnsignedShortArrayPrint(FILE* out); |
| 2942 | #endif |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2943 | #ifdef DEBUG |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2944 | void ExternalUnsignedShortArrayVerify(); |
| 2945 | #endif // DEBUG |
| 2946 | |
| 2947 | private: |
| 2948 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedShortArray); |
| 2949 | }; |
| 2950 | |
| 2951 | |
| 2952 | class ExternalIntArray: public ExternalArray { |
| 2953 | public: |
| 2954 | // Setter and getter. |
| 2955 | inline int32_t get(int index); |
| 2956 | inline void set(int index, int32_t value); |
| 2957 | |
| 2958 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 2959 | // and undefined. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2960 | MaybeObject* SetValue(uint32_t index, Object* value); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2961 | |
| 2962 | // Casting. |
| 2963 | static inline ExternalIntArray* cast(Object* obj); |
| 2964 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2965 | #ifdef OBJECT_PRINT |
| 2966 | inline void ExternalIntArrayPrint() { |
| 2967 | ExternalIntArrayPrint(stdout); |
| 2968 | } |
| 2969 | void ExternalIntArrayPrint(FILE* out); |
| 2970 | #endif |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2971 | #ifdef DEBUG |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2972 | void ExternalIntArrayVerify(); |
| 2973 | #endif // DEBUG |
| 2974 | |
| 2975 | private: |
| 2976 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalIntArray); |
| 2977 | }; |
| 2978 | |
| 2979 | |
| 2980 | class ExternalUnsignedIntArray: public ExternalArray { |
| 2981 | public: |
| 2982 | // Setter and getter. |
| 2983 | inline uint32_t get(int index); |
| 2984 | inline void set(int index, uint32_t value); |
| 2985 | |
| 2986 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 2987 | // and undefined. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 2988 | MaybeObject* SetValue(uint32_t index, Object* value); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2989 | |
| 2990 | // Casting. |
| 2991 | static inline ExternalUnsignedIntArray* cast(Object* obj); |
| 2992 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2993 | #ifdef OBJECT_PRINT |
| 2994 | inline void ExternalUnsignedIntArrayPrint() { |
| 2995 | ExternalUnsignedIntArrayPrint(stdout); |
| 2996 | } |
| 2997 | void ExternalUnsignedIntArrayPrint(FILE* out); |
| 2998 | #endif |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2999 | #ifdef DEBUG |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3000 | void ExternalUnsignedIntArrayVerify(); |
| 3001 | #endif // DEBUG |
| 3002 | |
| 3003 | private: |
| 3004 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedIntArray); |
| 3005 | }; |
| 3006 | |
| 3007 | |
| 3008 | class ExternalFloatArray: public ExternalArray { |
| 3009 | public: |
| 3010 | // Setter and getter. |
| 3011 | inline float get(int index); |
| 3012 | inline void set(int index, float value); |
| 3013 | |
| 3014 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3015 | // and undefined. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 3016 | MaybeObject* SetValue(uint32_t index, Object* value); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3017 | |
| 3018 | // Casting. |
| 3019 | static inline ExternalFloatArray* cast(Object* obj); |
| 3020 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3021 | #ifdef OBJECT_PRINT |
| 3022 | inline void ExternalFloatArrayPrint() { |
| 3023 | ExternalFloatArrayPrint(stdout); |
| 3024 | } |
| 3025 | void ExternalFloatArrayPrint(FILE* out); |
| 3026 | #endif |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3027 | #ifdef DEBUG |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3028 | void ExternalFloatArrayVerify(); |
| 3029 | #endif // DEBUG |
| 3030 | |
| 3031 | private: |
| 3032 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalFloatArray); |
| 3033 | }; |
| 3034 | |
| 3035 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3036 | // DeoptimizationInputData is a fixed array used to hold the deoptimization |
| 3037 | // data for code generated by the Hydrogen/Lithium compiler. It also |
| 3038 | // contains information about functions that were inlined. If N different |
| 3039 | // functions were inlined then first N elements of the literal array will |
| 3040 | // contain these functions. |
| 3041 | // |
| 3042 | // It can be empty. |
| 3043 | class DeoptimizationInputData: public FixedArray { |
| 3044 | public: |
| 3045 | // Layout description. Indices in the array. |
| 3046 | static const int kTranslationByteArrayIndex = 0; |
| 3047 | static const int kInlinedFunctionCountIndex = 1; |
| 3048 | static const int kLiteralArrayIndex = 2; |
| 3049 | static const int kOsrAstIdIndex = 3; |
| 3050 | static const int kOsrPcOffsetIndex = 4; |
| 3051 | static const int kFirstDeoptEntryIndex = 5; |
| 3052 | |
| 3053 | // Offsets of deopt entry elements relative to the start of the entry. |
| 3054 | static const int kAstIdOffset = 0; |
| 3055 | static const int kTranslationIndexOffset = 1; |
| 3056 | static const int kArgumentsStackHeightOffset = 2; |
| 3057 | static const int kDeoptEntrySize = 3; |
| 3058 | |
| 3059 | // Simple element accessors. |
| 3060 | #define DEFINE_ELEMENT_ACCESSORS(name, type) \ |
| 3061 | type* name() { \ |
| 3062 | return type::cast(get(k##name##Index)); \ |
| 3063 | } \ |
| 3064 | void Set##name(type* value) { \ |
| 3065 | set(k##name##Index, value); \ |
| 3066 | } |
| 3067 | |
| 3068 | DEFINE_ELEMENT_ACCESSORS(TranslationByteArray, ByteArray) |
| 3069 | DEFINE_ELEMENT_ACCESSORS(InlinedFunctionCount, Smi) |
| 3070 | DEFINE_ELEMENT_ACCESSORS(LiteralArray, FixedArray) |
| 3071 | DEFINE_ELEMENT_ACCESSORS(OsrAstId, Smi) |
| 3072 | DEFINE_ELEMENT_ACCESSORS(OsrPcOffset, Smi) |
| 3073 | |
| 3074 | // Unchecked accessor to be used during GC. |
| 3075 | FixedArray* UncheckedLiteralArray() { |
| 3076 | return reinterpret_cast<FixedArray*>(get(kLiteralArrayIndex)); |
| 3077 | } |
| 3078 | |
| 3079 | #undef DEFINE_ELEMENT_ACCESSORS |
| 3080 | |
| 3081 | // Accessors for elements of the ith deoptimization entry. |
| 3082 | #define DEFINE_ENTRY_ACCESSORS(name, type) \ |
| 3083 | type* name(int i) { \ |
| 3084 | return type::cast(get(IndexForEntry(i) + k##name##Offset)); \ |
| 3085 | } \ |
| 3086 | void Set##name(int i, type* value) { \ |
| 3087 | set(IndexForEntry(i) + k##name##Offset, value); \ |
| 3088 | } |
| 3089 | |
| 3090 | DEFINE_ENTRY_ACCESSORS(AstId, Smi) |
| 3091 | DEFINE_ENTRY_ACCESSORS(TranslationIndex, Smi) |
| 3092 | DEFINE_ENTRY_ACCESSORS(ArgumentsStackHeight, Smi) |
| 3093 | |
| 3094 | #undef DEFINE_ENTRY_ACCESSORS |
| 3095 | |
| 3096 | int DeoptCount() { |
| 3097 | return (length() - kFirstDeoptEntryIndex) / kDeoptEntrySize; |
| 3098 | } |
| 3099 | |
| 3100 | // Allocates a DeoptimizationInputData. |
| 3101 | MUST_USE_RESULT static MaybeObject* Allocate(int deopt_entry_count, |
| 3102 | PretenureFlag pretenure); |
| 3103 | |
| 3104 | // Casting. |
| 3105 | static inline DeoptimizationInputData* cast(Object* obj); |
| 3106 | |
| 3107 | #ifdef OBJECT_PRINT |
| 3108 | void DeoptimizationInputDataPrint(FILE* out); |
| 3109 | #endif |
| 3110 | |
| 3111 | private: |
| 3112 | static int IndexForEntry(int i) { |
| 3113 | return kFirstDeoptEntryIndex + (i * kDeoptEntrySize); |
| 3114 | } |
| 3115 | |
| 3116 | static int LengthFor(int entry_count) { |
| 3117 | return IndexForEntry(entry_count); |
| 3118 | } |
| 3119 | }; |
| 3120 | |
| 3121 | |
| 3122 | // DeoptimizationOutputData is a fixed array used to hold the deoptimization |
| 3123 | // data for code generated by the full compiler. |
| 3124 | // The format of the these objects is |
| 3125 | // [i * 2]: Ast ID for ith deoptimization. |
| 3126 | // [i * 2 + 1]: PC and state of ith deoptimization |
| 3127 | class DeoptimizationOutputData: public FixedArray { |
| 3128 | public: |
| 3129 | int DeoptPoints() { return length() / 2; } |
| 3130 | Smi* AstId(int index) { return Smi::cast(get(index * 2)); } |
| 3131 | void SetAstId(int index, Smi* id) { set(index * 2, id); } |
| 3132 | Smi* PcAndState(int index) { return Smi::cast(get(1 + index * 2)); } |
| 3133 | void SetPcAndState(int index, Smi* offset) { set(1 + index * 2, offset); } |
| 3134 | |
| 3135 | static int LengthOfFixedArray(int deopt_points) { |
| 3136 | return deopt_points * 2; |
| 3137 | } |
| 3138 | |
| 3139 | // Allocates a DeoptimizationOutputData. |
| 3140 | MUST_USE_RESULT static MaybeObject* Allocate(int number_of_deopt_points, |
| 3141 | PretenureFlag pretenure); |
| 3142 | |
| 3143 | // Casting. |
| 3144 | static inline DeoptimizationOutputData* cast(Object* obj); |
| 3145 | |
| 3146 | #ifdef OBJECT_PRINT |
| 3147 | void DeoptimizationOutputDataPrint(FILE* out); |
| 3148 | #endif |
| 3149 | }; |
| 3150 | |
| 3151 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 3152 | class SafepointEntry; |
| 3153 | |
| 3154 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3155 | // Code describes objects with on-the-fly generated machine code. |
| 3156 | class Code: public HeapObject { |
| 3157 | public: |
| 3158 | // Opaque data type for encapsulating code flags like kind, inline |
| 3159 | // cache state, and arguments count. |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 3160 | // FLAGS_MIN_VALUE and FLAGS_MAX_VALUE are specified to ensure that |
| 3161 | // enumeration type has correct value range (see Issue 830 for more details). |
| 3162 | enum Flags { |
| 3163 | FLAGS_MIN_VALUE = kMinInt, |
| 3164 | FLAGS_MAX_VALUE = kMaxInt |
| 3165 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3166 | |
| 3167 | enum Kind { |
| 3168 | FUNCTION, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3169 | OPTIMIZED_FUNCTION, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3170 | STUB, |
| 3171 | BUILTIN, |
| 3172 | LOAD_IC, |
| 3173 | KEYED_LOAD_IC, |
| 3174 | CALL_IC, |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3175 | KEYED_CALL_IC, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3176 | STORE_IC, |
| 3177 | KEYED_STORE_IC, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3178 | BINARY_OP_IC, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3179 | TYPE_RECORDING_BINARY_OP_IC, |
| 3180 | COMPARE_IC, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3181 | // 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] | 3182 | // Flags. |
| 3183 | |
| 3184 | // Pseudo-kinds. |
| 3185 | REGEXP = BUILTIN, |
| 3186 | FIRST_IC_KIND = LOAD_IC, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3187 | LAST_IC_KIND = COMPARE_IC |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3188 | }; |
| 3189 | |
| 3190 | enum { |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 3191 | NUMBER_OF_KINDS = LAST_IC_KIND + 1 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3192 | }; |
| 3193 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 3194 | typedef int ExtraICState; |
| 3195 | |
| 3196 | static const ExtraICState kNoExtraICState = 0; |
| 3197 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3198 | #ifdef ENABLE_DISASSEMBLER |
| 3199 | // Printing |
| 3200 | static const char* Kind2String(Kind kind); |
| 3201 | static const char* ICState2String(InlineCacheState state); |
| 3202 | static const char* PropertyType2String(PropertyType type); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 3203 | static void PrintExtraICState(FILE* out, Kind kind, ExtraICState extra); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3204 | inline void Disassemble(const char* name) { |
| 3205 | Disassemble(name, stdout); |
| 3206 | } |
| 3207 | void Disassemble(const char* name, FILE* out); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3208 | #endif // ENABLE_DISASSEMBLER |
| 3209 | |
| 3210 | // [instruction_size]: Size of the native instructions |
| 3211 | inline int instruction_size(); |
| 3212 | inline void set_instruction_size(int value); |
| 3213 | |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 3214 | // [relocation_info]: Code relocation information |
| 3215 | DECL_ACCESSORS(relocation_info, ByteArray) |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3216 | void InvalidateRelocation(); |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 3217 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3218 | // [deoptimization_data]: Array containing data for deopt. |
| 3219 | DECL_ACCESSORS(deoptimization_data, FixedArray) |
| 3220 | |
| 3221 | // Unchecked accessors to be used during GC. |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 3222 | inline ByteArray* unchecked_relocation_info(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3223 | inline FixedArray* unchecked_deoptimization_data(); |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 3224 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3225 | inline int relocation_size(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3226 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3227 | // [flags]: Various code flags. |
| 3228 | inline Flags flags(); |
| 3229 | inline void set_flags(Flags flags); |
| 3230 | |
| 3231 | // [flags]: Access to specific code flags. |
| 3232 | inline Kind kind(); |
| 3233 | inline InlineCacheState ic_state(); // Only valid for IC stubs. |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 3234 | inline ExtraICState extra_ic_state(); // Only valid for IC stubs. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3235 | inline InLoopFlag ic_in_loop(); // Only valid for IC stubs. |
| 3236 | inline PropertyType type(); // Only valid for monomorphic IC stubs. |
| 3237 | inline int arguments_count(); // Only valid for call IC stubs. |
| 3238 | |
| 3239 | // Testers for IC stub kinds. |
| 3240 | inline bool is_inline_cache_stub(); |
| 3241 | inline bool is_load_stub() { return kind() == LOAD_IC; } |
| 3242 | inline bool is_keyed_load_stub() { return kind() == KEYED_LOAD_IC; } |
| 3243 | inline bool is_store_stub() { return kind() == STORE_IC; } |
| 3244 | inline bool is_keyed_store_stub() { return kind() == KEYED_STORE_IC; } |
| 3245 | inline bool is_call_stub() { return kind() == CALL_IC; } |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3246 | inline bool is_keyed_call_stub() { return kind() == KEYED_CALL_IC; } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3247 | inline bool is_binary_op_stub() { return kind() == BINARY_OP_IC; } |
| 3248 | inline bool is_type_recording_binary_op_stub() { |
| 3249 | return kind() == TYPE_RECORDING_BINARY_OP_IC; |
| 3250 | } |
| 3251 | inline bool is_compare_ic_stub() { return kind() == COMPARE_IC; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3252 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3253 | // [major_key]: For kind STUB or BINARY_OP_IC, the major key. |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3254 | inline int major_key(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3255 | inline void set_major_key(int value); |
| 3256 | |
| 3257 | // [optimizable]: For FUNCTION kind, tells if it is optimizable. |
| 3258 | inline bool optimizable(); |
| 3259 | inline void set_optimizable(bool value); |
| 3260 | |
| 3261 | // [has_deoptimization_support]: For FUNCTION kind, tells if it has |
| 3262 | // deoptimization support. |
| 3263 | inline bool has_deoptimization_support(); |
| 3264 | inline void set_has_deoptimization_support(bool value); |
| 3265 | |
| 3266 | // [allow_osr_at_loop_nesting_level]: For FUNCTION kind, tells for |
| 3267 | // how long the function has been marked for OSR and therefore which |
| 3268 | // level of loop nesting we are willing to do on-stack replacement |
| 3269 | // for. |
| 3270 | inline void set_allow_osr_at_loop_nesting_level(int level); |
| 3271 | inline int allow_osr_at_loop_nesting_level(); |
| 3272 | |
| 3273 | // [stack_slots]: For kind OPTIMIZED_FUNCTION, the number of stack slots |
| 3274 | // reserved in the code prologue. |
| 3275 | inline unsigned stack_slots(); |
| 3276 | inline void set_stack_slots(unsigned slots); |
| 3277 | |
| 3278 | // [safepoint_table_start]: For kind OPTIMIZED_CODE, the offset in |
| 3279 | // the instruction stream where the safepoint table starts. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 3280 | inline unsigned safepoint_table_offset(); |
| 3281 | inline void set_safepoint_table_offset(unsigned offset); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3282 | |
| 3283 | // [stack_check_table_start]: For kind FUNCTION, the offset in the |
| 3284 | // instruction stream where the stack check table starts. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 3285 | inline unsigned stack_check_table_offset(); |
| 3286 | inline void set_stack_check_table_offset(unsigned offset); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3287 | |
| 3288 | // [check type]: For kind CALL_IC, tells how to check if the |
| 3289 | // receiver is valid for the given call. |
| 3290 | inline CheckType check_type(); |
| 3291 | inline void set_check_type(CheckType value); |
| 3292 | |
| 3293 | // [binary op type]: For all BINARY_OP_IC. |
| 3294 | inline byte binary_op_type(); |
| 3295 | inline void set_binary_op_type(byte value); |
| 3296 | |
| 3297 | // [type-recording binary op type]: For all TYPE_RECORDING_BINARY_OP_IC. |
| 3298 | inline byte type_recording_binary_op_type(); |
| 3299 | inline void set_type_recording_binary_op_type(byte value); |
| 3300 | inline byte type_recording_binary_op_result_type(); |
| 3301 | inline void set_type_recording_binary_op_result_type(byte value); |
| 3302 | |
| 3303 | // [compare state]: For kind compare IC stubs, tells what state the |
| 3304 | // stub is in. |
| 3305 | inline byte compare_state(); |
| 3306 | inline void set_compare_state(byte value); |
| 3307 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 3308 | // Get the safepoint entry for the given pc. |
| 3309 | SafepointEntry GetSafepointEntry(Address pc); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3310 | |
| 3311 | // Mark this code object as not having a stack check table. Assumes kind |
| 3312 | // is FUNCTION. |
| 3313 | void SetNoStackCheckTable(); |
| 3314 | |
| 3315 | // Find the first map in an IC stub. |
| 3316 | Map* FindFirstMap(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3317 | |
| 3318 | // Flags operations. |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 3319 | static inline Flags ComputeFlags( |
| 3320 | Kind kind, |
| 3321 | InLoopFlag in_loop = NOT_IN_LOOP, |
| 3322 | InlineCacheState ic_state = UNINITIALIZED, |
| 3323 | ExtraICState extra_ic_state = kNoExtraICState, |
| 3324 | PropertyType type = NORMAL, |
| 3325 | int argc = -1, |
| 3326 | InlineCacheHolderFlag holder = OWN_MAP); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3327 | |
| 3328 | static inline Flags ComputeMonomorphicFlags( |
| 3329 | Kind kind, |
| 3330 | PropertyType type, |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 3331 | ExtraICState extra_ic_state = kNoExtraICState, |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 3332 | InlineCacheHolderFlag holder = OWN_MAP, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3333 | InLoopFlag in_loop = NOT_IN_LOOP, |
| 3334 | int argc = -1); |
| 3335 | |
| 3336 | static inline Kind ExtractKindFromFlags(Flags flags); |
| 3337 | static inline InlineCacheState ExtractICStateFromFlags(Flags flags); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 3338 | static inline ExtraICState ExtractExtraICStateFromFlags(Flags flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3339 | static inline InLoopFlag ExtractICInLoopFromFlags(Flags flags); |
| 3340 | static inline PropertyType ExtractTypeFromFlags(Flags flags); |
| 3341 | static inline int ExtractArgumentsCountFromFlags(Flags flags); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 3342 | static inline InlineCacheHolderFlag ExtractCacheHolderFromFlags(Flags flags); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3343 | static inline Flags RemoveTypeFromFlags(Flags flags); |
| 3344 | |
| 3345 | // Convert a target address into a code object. |
| 3346 | static inline Code* GetCodeFromTargetAddress(Address address); |
| 3347 | |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 3348 | // Convert an entry address into an object. |
| 3349 | static inline Object* GetObjectFromEntryAddress(Address location_of_address); |
| 3350 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3351 | // Returns the address of the first instruction. |
| 3352 | inline byte* instruction_start(); |
| 3353 | |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 3354 | // Returns the address right after the last instruction. |
| 3355 | inline byte* instruction_end(); |
| 3356 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3357 | // Returns the size of the instructions, padding, and relocation information. |
| 3358 | inline int body_size(); |
| 3359 | |
| 3360 | // Returns the address of the first relocation info (read backwards!). |
| 3361 | inline byte* relocation_start(); |
| 3362 | |
| 3363 | // Code entry point. |
| 3364 | inline byte* entry(); |
| 3365 | |
| 3366 | // Returns true if pc is inside this object's instructions. |
| 3367 | inline bool contains(byte* pc); |
| 3368 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3369 | // Relocate the code by delta bytes. Called to signal that this code |
| 3370 | // object has been moved by delta bytes. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 3371 | void Relocate(intptr_t delta); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3372 | |
| 3373 | // Migrate code described by desc. |
| 3374 | void CopyFrom(const CodeDesc& desc); |
| 3375 | |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 3376 | // Returns the object size for a given body (used for allocation). |
| 3377 | static int SizeFor(int body_size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3378 | ASSERT_SIZE_TAG_ALIGNED(body_size); |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 3379 | return RoundUp(kHeaderSize + body_size, kCodeAlignment); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3380 | } |
| 3381 | |
| 3382 | // Calculate the size of the code object to report for log events. This takes |
| 3383 | // the layout of the code object into account. |
| 3384 | int ExecutableSize() { |
| 3385 | // Check that the assumptions about the layout of the code object holds. |
| 3386 | ASSERT_EQ(static_cast<int>(instruction_start() - address()), |
| 3387 | Code::kHeaderSize); |
| 3388 | return instruction_size() + Code::kHeaderSize; |
| 3389 | } |
| 3390 | |
| 3391 | // Locating source position. |
| 3392 | int SourcePosition(Address pc); |
| 3393 | int SourceStatementPosition(Address pc); |
| 3394 | |
| 3395 | // Casting. |
| 3396 | static inline Code* cast(Object* obj); |
| 3397 | |
| 3398 | // Dispatched behavior. |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 3399 | int CodeSize() { return SizeFor(body_size()); } |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 3400 | inline void CodeIterateBody(ObjectVisitor* v); |
| 3401 | |
| 3402 | template<typename StaticVisitor> |
| 3403 | inline void CodeIterateBody(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3404 | #ifdef OBJECT_PRINT |
| 3405 | inline void CodePrint() { |
| 3406 | CodePrint(stdout); |
| 3407 | } |
| 3408 | void CodePrint(FILE* out); |
| 3409 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3410 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3411 | void CodeVerify(); |
| 3412 | #endif |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3413 | |
| 3414 | // Max loop nesting marker used to postpose OSR. We don't take loop |
| 3415 | // nesting that is deeper than 5 levels into account. |
| 3416 | static const int kMaxLoopNestingMarker = 6; |
| 3417 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3418 | // Layout description. |
| 3419 | static const int kInstructionSizeOffset = HeapObject::kHeaderSize; |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 3420 | static const int kRelocationInfoOffset = kInstructionSizeOffset + kIntSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3421 | static const int kDeoptimizationDataOffset = |
| 3422 | kRelocationInfoOffset + kPointerSize; |
| 3423 | static const int kFlagsOffset = kDeoptimizationDataOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3424 | static const int kKindSpecificFlagsOffset = kFlagsOffset + kIntSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3425 | |
| 3426 | static const int kKindSpecificFlagsSize = 2 * kIntSize; |
| 3427 | |
| 3428 | static const int kHeaderPaddingStart = kKindSpecificFlagsOffset + |
| 3429 | kKindSpecificFlagsSize; |
| 3430 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3431 | // Add padding to align the instruction start following right after |
| 3432 | // the Code object header. |
| 3433 | static const int kHeaderSize = |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3434 | (kHeaderPaddingStart + kCodeAlignmentMask) & ~kCodeAlignmentMask; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3435 | |
| 3436 | // Byte offsets within kKindSpecificFlagsOffset. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3437 | static const int kStubMajorKeyOffset = kKindSpecificFlagsOffset; |
| 3438 | static const int kOptimizableOffset = kKindSpecificFlagsOffset; |
| 3439 | static const int kStackSlotsOffset = kKindSpecificFlagsOffset; |
| 3440 | static const int kCheckTypeOffset = kKindSpecificFlagsOffset; |
| 3441 | |
| 3442 | static const int kCompareStateOffset = kStubMajorKeyOffset + 1; |
| 3443 | static const int kBinaryOpTypeOffset = kStubMajorKeyOffset + 1; |
| 3444 | static const int kHasDeoptimizationSupportOffset = kOptimizableOffset + 1; |
| 3445 | |
| 3446 | static const int kBinaryOpReturnTypeOffset = kBinaryOpTypeOffset + 1; |
| 3447 | static const int kAllowOSRAtLoopNestingLevelOffset = |
| 3448 | kHasDeoptimizationSupportOffset + 1; |
| 3449 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 3450 | static const int kSafepointTableOffsetOffset = kStackSlotsOffset + kIntSize; |
| 3451 | static const int kStackCheckTableOffsetOffset = kStackSlotsOffset + kIntSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3452 | |
| 3453 | // Flags layout. |
| 3454 | static const int kFlagsICStateShift = 0; |
| 3455 | static const int kFlagsICInLoopShift = 3; |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 3456 | static const int kFlagsTypeShift = 4; |
| 3457 | static const int kFlagsKindShift = 7; |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 3458 | static const int kFlagsICHolderShift = 11; |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 3459 | static const int kFlagsExtraICStateShift = 12; |
| 3460 | static const int kFlagsArgumentsCountShift = 14; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3461 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3462 | static const int kFlagsICStateMask = 0x00000007; // 00000000111 |
| 3463 | static const int kFlagsICInLoopMask = 0x00000008; // 00000001000 |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 3464 | static const int kFlagsTypeMask = 0x00000070; // 00001110000 |
| 3465 | static const int kFlagsKindMask = 0x00000780; // 11110000000 |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 3466 | static const int kFlagsCacheInPrototypeMapMask = 0x00000800; |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 3467 | static const int kFlagsExtraICStateMask = 0x00003000; |
| 3468 | static const int kFlagsArgumentsCountMask = 0xFFFFC000; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3469 | |
| 3470 | static const int kFlagsNotUsedInLookup = |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 3471 | (kFlagsICInLoopMask | kFlagsTypeMask | kFlagsCacheInPrototypeMapMask); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3472 | |
| 3473 | private: |
| 3474 | DISALLOW_IMPLICIT_CONSTRUCTORS(Code); |
| 3475 | }; |
| 3476 | |
| 3477 | |
| 3478 | // All heap objects have a Map that describes their structure. |
| 3479 | // A Map contains information about: |
| 3480 | // - Size information about the object |
| 3481 | // - How to iterate over an object (for garbage collection) |
| 3482 | class Map: public HeapObject { |
| 3483 | public: |
| 3484 | // Instance size. |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 3485 | // Size in bytes or kVariableSizeSentinel if instances do not have |
| 3486 | // a fixed size. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3487 | inline int instance_size(); |
| 3488 | inline void set_instance_size(int value); |
| 3489 | |
| 3490 | // Count of properties allocated in the object. |
| 3491 | inline int inobject_properties(); |
| 3492 | inline void set_inobject_properties(int value); |
| 3493 | |
| 3494 | // Count of property fields pre-allocated in the object when first allocated. |
| 3495 | inline int pre_allocated_property_fields(); |
| 3496 | inline void set_pre_allocated_property_fields(int value); |
| 3497 | |
| 3498 | // Instance type. |
| 3499 | inline InstanceType instance_type(); |
| 3500 | inline void set_instance_type(InstanceType value); |
| 3501 | |
| 3502 | // Tells how many unused property fields are available in the |
| 3503 | // instance (only used for JSObject in fast mode). |
| 3504 | inline int unused_property_fields(); |
| 3505 | inline void set_unused_property_fields(int value); |
| 3506 | |
| 3507 | // Bit field. |
| 3508 | inline byte bit_field(); |
| 3509 | inline void set_bit_field(byte value); |
| 3510 | |
| 3511 | // Bit field 2. |
| 3512 | inline byte bit_field2(); |
| 3513 | inline void set_bit_field2(byte value); |
| 3514 | |
| 3515 | // Tells whether the object in the prototype property will be used |
| 3516 | // for instances created from this function. If the prototype |
| 3517 | // property is set to a value that is not a JSObject, the prototype |
| 3518 | // property will not be used to create instances of the function. |
| 3519 | // See ECMA-262, 13.2.2. |
| 3520 | inline void set_non_instance_prototype(bool value); |
| 3521 | inline bool has_non_instance_prototype(); |
| 3522 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3523 | // Tells whether function has special prototype property. If not, prototype |
| 3524 | // property will not be created when accessed (will return undefined), |
| 3525 | // and construction from this function will not be allowed. |
| 3526 | inline void set_function_with_prototype(bool value); |
| 3527 | inline bool function_with_prototype(); |
| 3528 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3529 | // Tells whether the instance with this map should be ignored by the |
| 3530 | // __proto__ accessor. |
| 3531 | inline void set_is_hidden_prototype() { |
| 3532 | set_bit_field(bit_field() | (1 << kIsHiddenPrototype)); |
| 3533 | } |
| 3534 | |
| 3535 | inline bool is_hidden_prototype() { |
| 3536 | return ((1 << kIsHiddenPrototype) & bit_field()) != 0; |
| 3537 | } |
| 3538 | |
| 3539 | // Records and queries whether the instance has a named interceptor. |
| 3540 | inline void set_has_named_interceptor() { |
| 3541 | set_bit_field(bit_field() | (1 << kHasNamedInterceptor)); |
| 3542 | } |
| 3543 | |
| 3544 | inline bool has_named_interceptor() { |
| 3545 | return ((1 << kHasNamedInterceptor) & bit_field()) != 0; |
| 3546 | } |
| 3547 | |
| 3548 | // Records and queries whether the instance has an indexed interceptor. |
| 3549 | inline void set_has_indexed_interceptor() { |
| 3550 | set_bit_field(bit_field() | (1 << kHasIndexedInterceptor)); |
| 3551 | } |
| 3552 | |
| 3553 | inline bool has_indexed_interceptor() { |
| 3554 | return ((1 << kHasIndexedInterceptor) & bit_field()) != 0; |
| 3555 | } |
| 3556 | |
| 3557 | // Tells whether the instance is undetectable. |
| 3558 | // An undetectable object is a special class of JSObject: 'typeof' operator |
| 3559 | // returns undefined, ToBoolean returns false. Otherwise it behaves like |
| 3560 | // a normal JS object. It is useful for implementing undetectable |
| 3561 | // document.all in Firefox & Safari. |
| 3562 | // See https://bugzilla.mozilla.org/show_bug.cgi?id=248549. |
| 3563 | inline void set_is_undetectable() { |
| 3564 | set_bit_field(bit_field() | (1 << kIsUndetectable)); |
| 3565 | } |
| 3566 | |
| 3567 | inline bool is_undetectable() { |
| 3568 | return ((1 << kIsUndetectable) & bit_field()) != 0; |
| 3569 | } |
| 3570 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3571 | // Tells whether the instance has a call-as-function handler. |
| 3572 | inline void set_has_instance_call_handler() { |
| 3573 | set_bit_field(bit_field() | (1 << kHasInstanceCallHandler)); |
| 3574 | } |
| 3575 | |
| 3576 | inline bool has_instance_call_handler() { |
| 3577 | return ((1 << kHasInstanceCallHandler) & bit_field()) != 0; |
| 3578 | } |
| 3579 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 3580 | inline void set_is_extensible(bool value); |
| 3581 | inline bool is_extensible(); |
| 3582 | |
| 3583 | // Tells whether the instance has fast elements. |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 3584 | // Equivalent to instance->GetElementsKind() == FAST_ELEMENTS. |
| 3585 | inline void set_has_fast_elements(bool value) { |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 3586 | if (value) { |
| 3587 | set_bit_field2(bit_field2() | (1 << kHasFastElements)); |
| 3588 | } else { |
| 3589 | set_bit_field2(bit_field2() & ~(1 << kHasFastElements)); |
| 3590 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 3591 | } |
| 3592 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 3593 | inline bool has_fast_elements() { |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 3594 | return ((1 << kHasFastElements) & bit_field2()) != 0; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 3595 | } |
| 3596 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 3597 | // Tells whether an instance has pixel array elements. |
| 3598 | inline void set_has_pixel_array_elements(bool value) { |
| 3599 | if (value) { |
| 3600 | set_bit_field2(bit_field2() | (1 << kHasPixelArrayElements)); |
| 3601 | } else { |
| 3602 | set_bit_field2(bit_field2() & ~(1 << kHasPixelArrayElements)); |
| 3603 | } |
| 3604 | } |
| 3605 | |
| 3606 | inline bool has_pixel_array_elements() { |
| 3607 | return ((1 << kHasPixelArrayElements) & bit_field2()) != 0; |
| 3608 | } |
| 3609 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3610 | // Tells whether the map is attached to SharedFunctionInfo |
| 3611 | // (for inobject slack tracking). |
| 3612 | inline void set_attached_to_shared_function_info(bool value); |
| 3613 | |
| 3614 | inline bool attached_to_shared_function_info(); |
| 3615 | |
| 3616 | // Tells whether the map is shared between objects that may have different |
| 3617 | // behavior. If true, the map should never be modified, instead a clone |
| 3618 | // should be created and modified. |
| 3619 | inline void set_is_shared(bool value); |
| 3620 | |
| 3621 | inline bool is_shared(); |
| 3622 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3623 | // Tells whether the instance needs security checks when accessing its |
| 3624 | // properties. |
| 3625 | inline void set_is_access_check_needed(bool access_check_needed); |
| 3626 | inline bool is_access_check_needed(); |
| 3627 | |
| 3628 | // [prototype]: implicit prototype object. |
| 3629 | DECL_ACCESSORS(prototype, Object) |
| 3630 | |
| 3631 | // [constructor]: points back to the function responsible for this map. |
| 3632 | DECL_ACCESSORS(constructor, Object) |
| 3633 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3634 | inline JSFunction* unchecked_constructor(); |
| 3635 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3636 | // [instance descriptors]: describes the object. |
| 3637 | DECL_ACCESSORS(instance_descriptors, DescriptorArray) |
| 3638 | |
| 3639 | // [stub cache]: contains stubs compiled for this map. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3640 | DECL_ACCESSORS(code_cache, Object) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3641 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3642 | // Lookup in the map's instance descriptors and fill out the result |
| 3643 | // with the given holder if the name is found. The holder may be |
| 3644 | // NULL when this function is used from the compiler. |
| 3645 | void LookupInDescriptors(JSObject* holder, |
| 3646 | String* name, |
| 3647 | LookupResult* result); |
| 3648 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 3649 | MUST_USE_RESULT MaybeObject* CopyDropDescriptors(); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3650 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 3651 | MUST_USE_RESULT MaybeObject* CopyNormalized(PropertyNormalizationMode mode, |
| 3652 | NormalizedMapSharingMode sharing); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3653 | |
| 3654 | // Returns a copy of the map, with all transitions dropped from the |
| 3655 | // instance descriptors. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 3656 | MUST_USE_RESULT MaybeObject* CopyDropTransitions(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3657 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 3658 | // Returns this map if it has the fast elements bit set, otherwise |
| 3659 | // returns a copy of the map, with all transitions dropped from the |
| 3660 | // descriptors and the fast elements bit set. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 3661 | MUST_USE_RESULT inline MaybeObject* GetFastElementsMap(); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 3662 | |
| 3663 | // Returns this map if it has the fast elements bit cleared, |
| 3664 | // otherwise returns a copy of the map, with all transitions dropped |
| 3665 | // from the descriptors and the fast elements bit cleared. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 3666 | MUST_USE_RESULT inline MaybeObject* GetSlowElementsMap(); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 3667 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 3668 | // Returns this map if it has the pixel array elements bit is set, otherwise |
| 3669 | // returns a copy of the map, with all transitions dropped from the |
| 3670 | // descriptors and the pixel array elements bit set. |
| 3671 | MUST_USE_RESULT inline MaybeObject* GetPixelArrayElementsMap(); |
| 3672 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3673 | // Returns the property index for name (only valid for FAST MODE). |
| 3674 | int PropertyIndexFor(String* name); |
| 3675 | |
| 3676 | // Returns the next free property index (only valid for FAST MODE). |
| 3677 | int NextFreePropertyIndex(); |
| 3678 | |
| 3679 | // Returns the number of properties described in instance_descriptors. |
| 3680 | int NumberOfDescribedProperties(); |
| 3681 | |
| 3682 | // Casting. |
| 3683 | static inline Map* cast(Object* obj); |
| 3684 | |
| 3685 | // Locate an accessor in the instance descriptor. |
| 3686 | AccessorDescriptor* FindAccessor(String* name); |
| 3687 | |
| 3688 | // Code cache operations. |
| 3689 | |
| 3690 | // Clears the code cache. |
| 3691 | inline void ClearCodeCache(); |
| 3692 | |
| 3693 | // Update code cache. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 3694 | MUST_USE_RESULT MaybeObject* UpdateCodeCache(String* name, Code* code); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3695 | |
| 3696 | // Returns the found code or undefined if absent. |
| 3697 | Object* FindInCodeCache(String* name, Code::Flags flags); |
| 3698 | |
| 3699 | // Returns the non-negative index of the code object if it is in the |
| 3700 | // cache and -1 otherwise. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3701 | int IndexInCodeCache(Object* name, Code* code); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3702 | |
| 3703 | // Removes a code object from the code cache at the given index. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3704 | void RemoveFromCodeCache(String* name, Code* code, int index); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3705 | |
| 3706 | // For every transition in this map, makes the transition's |
| 3707 | // target's prototype pointer point back to this map. |
| 3708 | // This is undone in MarkCompactCollector::ClearNonLiveTransitions(). |
| 3709 | void CreateBackPointers(); |
| 3710 | |
| 3711 | // Set all map transitions from this map to dead maps to null. |
| 3712 | // Also, restore the original prototype on the targets of these |
| 3713 | // transitions, so that we do not process this map again while |
| 3714 | // following back pointers. |
| 3715 | void ClearNonLiveTransitions(Object* real_prototype); |
| 3716 | |
| 3717 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3718 | #ifdef OBJECT_PRINT |
| 3719 | inline void MapPrint() { |
| 3720 | MapPrint(stdout); |
| 3721 | } |
| 3722 | void MapPrint(FILE* out); |
| 3723 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3724 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3725 | void MapVerify(); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3726 | void SharedMapVerify(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3727 | #endif |
| 3728 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 3729 | inline int visitor_id(); |
| 3730 | inline void set_visitor_id(int visitor_id); |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 3731 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3732 | typedef void (*TraverseCallback)(Map* map, void* data); |
| 3733 | |
| 3734 | void TraverseTransitionTree(TraverseCallback callback, void* data); |
| 3735 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3736 | static const int kMaxPreAllocatedPropertyFields = 255; |
| 3737 | |
| 3738 | // Layout description. |
| 3739 | static const int kInstanceSizesOffset = HeapObject::kHeaderSize; |
| 3740 | static const int kInstanceAttributesOffset = kInstanceSizesOffset + kIntSize; |
| 3741 | static const int kPrototypeOffset = kInstanceAttributesOffset + kIntSize; |
| 3742 | static const int kConstructorOffset = kPrototypeOffset + kPointerSize; |
| 3743 | static const int kInstanceDescriptorsOffset = |
| 3744 | kConstructorOffset + kPointerSize; |
| 3745 | static const int kCodeCacheOffset = kInstanceDescriptorsOffset + kPointerSize; |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 3746 | static const int kPadStart = kCodeCacheOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3747 | static const int kSize = MAP_POINTER_ALIGN(kPadStart); |
| 3748 | |
| 3749 | // Layout of pointer fields. Heap iteration code relies on them |
| 3750 | // being continiously allocated. |
| 3751 | static const int kPointerFieldsBeginOffset = Map::kPrototypeOffset; |
| 3752 | static const int kPointerFieldsEndOffset = |
| 3753 | Map::kCodeCacheOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3754 | |
| 3755 | // Byte offsets within kInstanceSizesOffset. |
| 3756 | static const int kInstanceSizeOffset = kInstanceSizesOffset + 0; |
| 3757 | static const int kInObjectPropertiesByte = 1; |
| 3758 | static const int kInObjectPropertiesOffset = |
| 3759 | kInstanceSizesOffset + kInObjectPropertiesByte; |
| 3760 | static const int kPreAllocatedPropertyFieldsByte = 2; |
| 3761 | static const int kPreAllocatedPropertyFieldsOffset = |
| 3762 | kInstanceSizesOffset + kPreAllocatedPropertyFieldsByte; |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 3763 | static const int kVisitorIdByte = 3; |
| 3764 | static const int kVisitorIdOffset = kInstanceSizesOffset + kVisitorIdByte; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3765 | |
| 3766 | // Byte offsets within kInstanceAttributesOffset attributes. |
| 3767 | static const int kInstanceTypeOffset = kInstanceAttributesOffset + 0; |
| 3768 | static const int kUnusedPropertyFieldsOffset = kInstanceAttributesOffset + 1; |
| 3769 | static const int kBitFieldOffset = kInstanceAttributesOffset + 2; |
| 3770 | static const int kBitField2Offset = kInstanceAttributesOffset + 3; |
| 3771 | |
| 3772 | STATIC_CHECK(kInstanceTypeOffset == Internals::kMapInstanceTypeOffset); |
| 3773 | |
| 3774 | // Bit positions for bit field. |
| 3775 | static const int kUnused = 0; // To be used for marking recently used maps. |
| 3776 | static const int kHasNonInstancePrototype = 1; |
| 3777 | static const int kIsHiddenPrototype = 2; |
| 3778 | static const int kHasNamedInterceptor = 3; |
| 3779 | static const int kHasIndexedInterceptor = 4; |
| 3780 | static const int kIsUndetectable = 5; |
| 3781 | static const int kHasInstanceCallHandler = 6; |
| 3782 | static const int kIsAccessCheckNeeded = 7; |
| 3783 | |
| 3784 | // Bit positions for bit field 2 |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 3785 | static const int kIsExtensible = 0; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3786 | static const int kFunctionWithPrototype = 1; |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 3787 | static const int kHasFastElements = 2; |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 3788 | static const int kStringWrapperSafeForDefaultValueOf = 3; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3789 | static const int kAttachedToSharedFunctionInfo = 4; |
| 3790 | static const int kIsShared = 5; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 3791 | static const int kHasPixelArrayElements = 6; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3792 | |
| 3793 | // Layout of the default cache. It holds alternating name and code objects. |
| 3794 | static const int kCodeCacheEntrySize = 2; |
| 3795 | static const int kCodeCacheEntryNameOffset = 0; |
| 3796 | static const int kCodeCacheEntryCodeOffset = 1; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3797 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 3798 | typedef FixedBodyDescriptor<kPointerFieldsBeginOffset, |
| 3799 | kPointerFieldsEndOffset, |
| 3800 | kSize> BodyDescriptor; |
| 3801 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3802 | private: |
| 3803 | DISALLOW_IMPLICIT_CONSTRUCTORS(Map); |
| 3804 | }; |
| 3805 | |
| 3806 | |
| 3807 | // An abstract superclass, a marker class really, for simple structure classes. |
| 3808 | // It doesn't carry much functionality but allows struct classes to me |
| 3809 | // identified in the type system. |
| 3810 | class Struct: public HeapObject { |
| 3811 | public: |
| 3812 | inline void InitializeBody(int object_size); |
| 3813 | static inline Struct* cast(Object* that); |
| 3814 | }; |
| 3815 | |
| 3816 | |
| 3817 | // Script describes a script which has been added to the VM. |
| 3818 | class Script: public Struct { |
| 3819 | public: |
| 3820 | // Script types. |
| 3821 | enum Type { |
| 3822 | TYPE_NATIVE = 0, |
| 3823 | TYPE_EXTENSION = 1, |
| 3824 | TYPE_NORMAL = 2 |
| 3825 | }; |
| 3826 | |
| 3827 | // Script compilation types. |
| 3828 | enum CompilationType { |
| 3829 | COMPILATION_TYPE_HOST = 0, |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 3830 | COMPILATION_TYPE_EVAL = 1 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3831 | }; |
| 3832 | |
| 3833 | // [source]: the script source. |
| 3834 | DECL_ACCESSORS(source, Object) |
| 3835 | |
| 3836 | // [name]: the script name. |
| 3837 | DECL_ACCESSORS(name, Object) |
| 3838 | |
| 3839 | // [id]: the script id. |
| 3840 | DECL_ACCESSORS(id, Object) |
| 3841 | |
| 3842 | // [line_offset]: script line offset in resource from where it was extracted. |
| 3843 | DECL_ACCESSORS(line_offset, Smi) |
| 3844 | |
| 3845 | // [column_offset]: script column offset in resource from where it was |
| 3846 | // extracted. |
| 3847 | DECL_ACCESSORS(column_offset, Smi) |
| 3848 | |
| 3849 | // [data]: additional data associated with this script. |
| 3850 | DECL_ACCESSORS(data, Object) |
| 3851 | |
| 3852 | // [context_data]: context data for the context this script was compiled in. |
| 3853 | DECL_ACCESSORS(context_data, Object) |
| 3854 | |
| 3855 | // [wrapper]: the wrapper cache. |
| 3856 | DECL_ACCESSORS(wrapper, Proxy) |
| 3857 | |
| 3858 | // [type]: the script type. |
| 3859 | DECL_ACCESSORS(type, Smi) |
| 3860 | |
| 3861 | // [compilation]: how the the script was compiled. |
| 3862 | DECL_ACCESSORS(compilation_type, Smi) |
| 3863 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 3864 | // [line_ends]: FixedArray of line ends positions. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3865 | DECL_ACCESSORS(line_ends, Object) |
| 3866 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 3867 | // [eval_from_shared]: for eval scripts the shared funcion info for the |
| 3868 | // function from which eval was called. |
| 3869 | DECL_ACCESSORS(eval_from_shared, Object) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3870 | |
| 3871 | // [eval_from_instructions_offset]: the instruction offset in the code for the |
| 3872 | // function from which eval was called where eval was called. |
| 3873 | DECL_ACCESSORS(eval_from_instructions_offset, Smi) |
| 3874 | |
| 3875 | static inline Script* cast(Object* obj); |
| 3876 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3877 | // If script source is an external string, check that the underlying |
| 3878 | // resource is accessible. Otherwise, always return true. |
| 3879 | inline bool HasValidSource(); |
| 3880 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3881 | #ifdef OBJECT_PRINT |
| 3882 | inline void ScriptPrint() { |
| 3883 | ScriptPrint(stdout); |
| 3884 | } |
| 3885 | void ScriptPrint(FILE* out); |
| 3886 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3887 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3888 | void ScriptVerify(); |
| 3889 | #endif |
| 3890 | |
| 3891 | static const int kSourceOffset = HeapObject::kHeaderSize; |
| 3892 | static const int kNameOffset = kSourceOffset + kPointerSize; |
| 3893 | static const int kLineOffsetOffset = kNameOffset + kPointerSize; |
| 3894 | static const int kColumnOffsetOffset = kLineOffsetOffset + kPointerSize; |
| 3895 | static const int kDataOffset = kColumnOffsetOffset + kPointerSize; |
| 3896 | static const int kContextOffset = kDataOffset + kPointerSize; |
| 3897 | static const int kWrapperOffset = kContextOffset + kPointerSize; |
| 3898 | static const int kTypeOffset = kWrapperOffset + kPointerSize; |
| 3899 | static const int kCompilationTypeOffset = kTypeOffset + kPointerSize; |
| 3900 | static const int kLineEndsOffset = kCompilationTypeOffset + kPointerSize; |
| 3901 | static const int kIdOffset = kLineEndsOffset + kPointerSize; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 3902 | static const int kEvalFromSharedOffset = kIdOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3903 | static const int kEvalFrominstructionsOffsetOffset = |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 3904 | kEvalFromSharedOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3905 | static const int kSize = kEvalFrominstructionsOffsetOffset + kPointerSize; |
| 3906 | |
| 3907 | private: |
| 3908 | DISALLOW_IMPLICIT_CONSTRUCTORS(Script); |
| 3909 | }; |
| 3910 | |
| 3911 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3912 | // List of builtin functions we want to identify to improve code |
| 3913 | // generation. |
| 3914 | // |
| 3915 | // Each entry has a name of a global object property holding an object |
| 3916 | // optionally followed by ".prototype", a name of a builtin function |
| 3917 | // on the object (the one the id is set for), and a label. |
| 3918 | // |
| 3919 | // Installation of ids for the selected builtin functions is handled |
| 3920 | // by the bootstrapper. |
| 3921 | // |
| 3922 | // NOTE: Order is important: math functions should be at the end of |
| 3923 | // the list and MathFloor should be the first math function. |
| 3924 | #define FUNCTIONS_WITH_ID_LIST(V) \ |
| 3925 | V(Array.prototype, push, ArrayPush) \ |
| 3926 | V(Array.prototype, pop, ArrayPop) \ |
| 3927 | V(String.prototype, charCodeAt, StringCharCodeAt) \ |
| 3928 | V(String.prototype, charAt, StringCharAt) \ |
| 3929 | V(String, fromCharCode, StringFromCharCode) \ |
| 3930 | V(Math, floor, MathFloor) \ |
| 3931 | V(Math, round, MathRound) \ |
| 3932 | V(Math, ceil, MathCeil) \ |
| 3933 | V(Math, abs, MathAbs) \ |
| 3934 | V(Math, log, MathLog) \ |
| 3935 | V(Math, sin, MathSin) \ |
| 3936 | V(Math, cos, MathCos) \ |
| 3937 | V(Math, tan, MathTan) \ |
| 3938 | V(Math, asin, MathASin) \ |
| 3939 | V(Math, acos, MathACos) \ |
| 3940 | V(Math, atan, MathATan) \ |
| 3941 | V(Math, exp, MathExp) \ |
| 3942 | V(Math, sqrt, MathSqrt) \ |
| 3943 | V(Math, pow, MathPow) |
| 3944 | |
| 3945 | |
| 3946 | enum BuiltinFunctionId { |
| 3947 | #define DECLARE_FUNCTION_ID(ignored1, ignore2, name) \ |
| 3948 | k##name, |
| 3949 | FUNCTIONS_WITH_ID_LIST(DECLARE_FUNCTION_ID) |
| 3950 | #undef DECLARE_FUNCTION_ID |
| 3951 | // Fake id for a special case of Math.pow. Note, it continues the |
| 3952 | // list of math functions. |
| 3953 | kMathPowHalf, |
| 3954 | kFirstMathFunctionId = kMathFloor |
| 3955 | }; |
| 3956 | |
| 3957 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3958 | // SharedFunctionInfo describes the JSFunction information that can be |
| 3959 | // shared by multiple instances of the function. |
| 3960 | class SharedFunctionInfo: public HeapObject { |
| 3961 | public: |
| 3962 | // [name]: Function name. |
| 3963 | DECL_ACCESSORS(name, Object) |
| 3964 | |
| 3965 | // [code]: Function code. |
| 3966 | DECL_ACCESSORS(code, Code) |
| 3967 | |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 3968 | // [scope_info]: Scope info. |
| 3969 | DECL_ACCESSORS(scope_info, SerializedScopeInfo) |
| 3970 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3971 | // [construct stub]: Code stub for constructing instances of this function. |
| 3972 | DECL_ACCESSORS(construct_stub, Code) |
| 3973 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 3974 | inline Code* unchecked_code(); |
| 3975 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3976 | // Returns if this function has been compiled to native code yet. |
| 3977 | inline bool is_compiled(); |
| 3978 | |
| 3979 | // [length]: The function length - usually the number of declared parameters. |
| 3980 | // Use up to 2^30 parameters. |
| 3981 | inline int length(); |
| 3982 | inline void set_length(int value); |
| 3983 | |
| 3984 | // [formal parameter count]: The declared number of parameters. |
| 3985 | inline int formal_parameter_count(); |
| 3986 | inline void set_formal_parameter_count(int value); |
| 3987 | |
| 3988 | // Set the formal parameter count so the function code will be |
| 3989 | // called without using argument adaptor frames. |
| 3990 | inline void DontAdaptArguments(); |
| 3991 | |
| 3992 | // [expected_nof_properties]: Expected number of properties for the function. |
| 3993 | inline int expected_nof_properties(); |
| 3994 | inline void set_expected_nof_properties(int value); |
| 3995 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3996 | // Inobject slack tracking is the way to reclaim unused inobject space. |
| 3997 | // |
| 3998 | // The instance size is initially determined by adding some slack to |
| 3999 | // expected_nof_properties (to allow for a few extra properties added |
| 4000 | // after the constructor). There is no guarantee that the extra space |
| 4001 | // will not be wasted. |
| 4002 | // |
| 4003 | // Here is the algorithm to reclaim the unused inobject space: |
| 4004 | // - Detect the first constructor call for this SharedFunctionInfo. |
| 4005 | // When it happens enter the "in progress" state: remember the |
| 4006 | // constructor's initial_map and install a special construct stub that |
| 4007 | // counts constructor calls. |
| 4008 | // - While the tracking is in progress create objects filled with |
| 4009 | // one_pointer_filler_map instead of undefined_value. This way they can be |
| 4010 | // resized quickly and safely. |
| 4011 | // - Once enough (kGenerousAllocationCount) objects have been created |
| 4012 | // compute the 'slack' (traverse the map transition tree starting from the |
| 4013 | // initial_map and find the lowest value of unused_property_fields). |
| 4014 | // - Traverse the transition tree again and decrease the instance size |
| 4015 | // of every map. Existing objects will resize automatically (they are |
| 4016 | // filled with one_pointer_filler_map). All further allocations will |
| 4017 | // use the adjusted instance size. |
| 4018 | // - Decrease expected_nof_properties so that an allocations made from |
| 4019 | // another context will use the adjusted instance size too. |
| 4020 | // - Exit "in progress" state by clearing the reference to the initial_map |
| 4021 | // and setting the regular construct stub (generic or inline). |
| 4022 | // |
| 4023 | // The above is the main event sequence. Some special cases are possible |
| 4024 | // while the tracking is in progress: |
| 4025 | // |
| 4026 | // - GC occurs. |
| 4027 | // Check if the initial_map is referenced by any live objects (except this |
| 4028 | // SharedFunctionInfo). If it is, continue tracking as usual. |
| 4029 | // If it is not, clear the reference and reset the tracking state. The |
| 4030 | // tracking will be initiated again on the next constructor call. |
| 4031 | // |
| 4032 | // - The constructor is called from another context. |
| 4033 | // Immediately complete the tracking, perform all the necessary changes |
| 4034 | // to maps. This is necessary because there is no efficient way to track |
| 4035 | // multiple initial_maps. |
| 4036 | // Proceed to create an object in the current context (with the adjusted |
| 4037 | // size). |
| 4038 | // |
| 4039 | // - A different constructor function sharing the same SharedFunctionInfo is |
| 4040 | // called in the same context. This could be another closure in the same |
| 4041 | // context, or the first function could have been disposed. |
| 4042 | // This is handled the same way as the previous case. |
| 4043 | // |
| 4044 | // Important: inobject slack tracking is not attempted during the snapshot |
| 4045 | // creation. |
| 4046 | |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 4047 | static const int kGenerousAllocationCount = 8; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4048 | |
| 4049 | // [construction_count]: Counter for constructor calls made during |
| 4050 | // the tracking phase. |
| 4051 | inline int construction_count(); |
| 4052 | inline void set_construction_count(int value); |
| 4053 | |
| 4054 | // [initial_map]: initial map of the first function called as a constructor. |
| 4055 | // Saved for the duration of the tracking phase. |
| 4056 | // This is a weak link (GC resets it to undefined_value if no other live |
| 4057 | // object reference this map). |
| 4058 | DECL_ACCESSORS(initial_map, Object) |
| 4059 | |
| 4060 | // True if the initial_map is not undefined and the countdown stub is |
| 4061 | // installed. |
| 4062 | inline bool IsInobjectSlackTrackingInProgress(); |
| 4063 | |
| 4064 | // Starts the tracking. |
| 4065 | // Stores the initial map and installs the countdown stub. |
| 4066 | // IsInobjectSlackTrackingInProgress is normally true after this call, |
| 4067 | // except when tracking have not been started (e.g. the map has no unused |
| 4068 | // properties or the snapshot is being built). |
| 4069 | void StartInobjectSlackTracking(Map* map); |
| 4070 | |
| 4071 | // Completes the tracking. |
| 4072 | // IsInobjectSlackTrackingInProgress is false after this call. |
| 4073 | void CompleteInobjectSlackTracking(); |
| 4074 | |
| 4075 | // Clears the initial_map before the GC marking phase to ensure the reference |
| 4076 | // is weak. IsInobjectSlackTrackingInProgress is false after this call. |
| 4077 | void DetachInitialMap(); |
| 4078 | |
| 4079 | // Restores the link to the initial map after the GC marking phase. |
| 4080 | // IsInobjectSlackTrackingInProgress is true after this call. |
| 4081 | void AttachInitialMap(Map* map); |
| 4082 | |
| 4083 | // False if there are definitely no live objects created from this function. |
| 4084 | // True if live objects _may_ exist (existence not guaranteed). |
| 4085 | // May go back from true to false after GC. |
| 4086 | inline bool live_objects_may_exist(); |
| 4087 | |
| 4088 | inline void set_live_objects_may_exist(bool value); |
| 4089 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4090 | // [instance class name]: class name for instances. |
| 4091 | DECL_ACCESSORS(instance_class_name, Object) |
| 4092 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4093 | // [function data]: This field holds some additional data for function. |
| 4094 | // Currently it either has FunctionTemplateInfo to make benefit the API |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4095 | // or Smi identifying a builtin function. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4096 | // In the long run we don't want all functions to have this field but |
| 4097 | // we can fix that when we have a better model for storing hidden data |
| 4098 | // on objects. |
| 4099 | DECL_ACCESSORS(function_data, Object) |
| 4100 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4101 | inline bool IsApiFunction(); |
| 4102 | inline FunctionTemplateInfo* get_api_func_data(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4103 | inline bool HasBuiltinFunctionId(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4104 | inline BuiltinFunctionId builtin_function_id(); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4105 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4106 | // [script info]: Script from which the function originates. |
| 4107 | DECL_ACCESSORS(script, Object) |
| 4108 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4109 | // [num_literals]: Number of literals used by this function. |
| 4110 | inline int num_literals(); |
| 4111 | inline void set_num_literals(int value); |
| 4112 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4113 | // [start_position_and_type]: Field used to store both the source code |
| 4114 | // position, whether or not the function is a function expression, |
| 4115 | // and whether or not the function is a toplevel function. The two |
| 4116 | // least significants bit indicates whether the function is an |
| 4117 | // expression and the rest contains the source code position. |
| 4118 | inline int start_position_and_type(); |
| 4119 | inline void set_start_position_and_type(int value); |
| 4120 | |
| 4121 | // [debug info]: Debug information. |
| 4122 | DECL_ACCESSORS(debug_info, Object) |
| 4123 | |
| 4124 | // [inferred name]: Name inferred from variable or property |
| 4125 | // assignment of this function. Used to facilitate debugging and |
| 4126 | // profiling of JavaScript code written in OO style, where almost |
| 4127 | // all functions are anonymous but are assigned to object |
| 4128 | // properties. |
| 4129 | DECL_ACCESSORS(inferred_name, String) |
| 4130 | |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 4131 | // The function's name if it is non-empty, otherwise the inferred name. |
| 4132 | String* DebugName(); |
| 4133 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4134 | // Position of the 'function' token in the script source. |
| 4135 | inline int function_token_position(); |
| 4136 | inline void set_function_token_position(int function_token_position); |
| 4137 | |
| 4138 | // Position of this function in the script source. |
| 4139 | inline int start_position(); |
| 4140 | inline void set_start_position(int start_position); |
| 4141 | |
| 4142 | // End position of this function in the script source. |
| 4143 | inline int end_position(); |
| 4144 | inline void set_end_position(int end_position); |
| 4145 | |
| 4146 | // Is this function a function expression in the source code. |
| 4147 | inline bool is_expression(); |
| 4148 | inline void set_is_expression(bool value); |
| 4149 | |
| 4150 | // Is this function a top-level function (scripts, evals). |
| 4151 | inline bool is_toplevel(); |
| 4152 | inline void set_is_toplevel(bool value); |
| 4153 | |
| 4154 | // Bit field containing various information collected by the compiler to |
| 4155 | // drive optimization. |
| 4156 | inline int compiler_hints(); |
| 4157 | inline void set_compiler_hints(int value); |
| 4158 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4159 | // A counter used to determine when to stress the deoptimizer with a |
| 4160 | // deopt. |
| 4161 | inline Smi* deopt_counter(); |
| 4162 | inline void set_deopt_counter(Smi* counter); |
| 4163 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4164 | // Add information on assignments of the form this.x = ...; |
| 4165 | void SetThisPropertyAssignmentsInfo( |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4166 | bool has_only_simple_this_property_assignments, |
| 4167 | FixedArray* this_property_assignments); |
| 4168 | |
| 4169 | // Clear information on assignments of the form this.x = ...; |
| 4170 | void ClearThisPropertyAssignmentsInfo(); |
| 4171 | |
| 4172 | // Indicate that this function only consists of assignments of the form |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4173 | // this.x = y; where y is either a constant or refers to an argument. |
| 4174 | inline bool has_only_simple_this_property_assignments(); |
| 4175 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 4176 | inline bool try_full_codegen(); |
| 4177 | inline void set_try_full_codegen(bool flag); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4178 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4179 | // Indicates if this function can be lazy compiled. |
| 4180 | // This is used to determine if we can safely flush code from a function |
| 4181 | // when doing GC if we expect that the function will no longer be used. |
| 4182 | inline bool allows_lazy_compilation(); |
| 4183 | inline void set_allows_lazy_compilation(bool flag); |
| 4184 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 4185 | // Indicates how many full GCs this function has survived with assigned |
| 4186 | // code object. Used to determine when it is relatively safe to flush |
| 4187 | // this code object and replace it with lazy compilation stub. |
| 4188 | // Age is reset when GC notices that the code object is referenced |
| 4189 | // from the stack or compilation cache. |
| 4190 | inline int code_age(); |
| 4191 | inline void set_code_age(int age); |
| 4192 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4193 | // Indicates whether optimizations have been disabled for this |
| 4194 | // shared function info. If a function is repeatedly optimized or if |
| 4195 | // we cannot optimize the function we disable optimization to avoid |
| 4196 | // spending time attempting to optimize it again. |
| 4197 | inline bool optimization_disabled(); |
| 4198 | inline void set_optimization_disabled(bool value); |
| 4199 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 4200 | // Indicates whether the function is a strict mode function. |
| 4201 | inline bool strict_mode(); |
| 4202 | inline void set_strict_mode(bool value); |
| 4203 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4204 | // Indicates whether or not the code in the shared function support |
| 4205 | // deoptimization. |
| 4206 | inline bool has_deoptimization_support(); |
| 4207 | |
| 4208 | // Enable deoptimization support through recompiled code. |
| 4209 | void EnableDeoptimizationSupport(Code* recompiled); |
| 4210 | |
| 4211 | // Lookup the bailout ID and ASSERT that it exists in the non-optimized |
| 4212 | // code, returns whether it asserted (i.e., always true if assertions are |
| 4213 | // disabled). |
| 4214 | bool VerifyBailoutId(int id); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 4215 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 4216 | // Check whether a inlined constructor can be generated with the given |
| 4217 | // prototype. |
| 4218 | bool CanGenerateInlineConstructor(Object* prototype); |
| 4219 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4220 | // Prevents further attempts to generate inline constructors. |
| 4221 | // To be called if generation failed for any reason. |
| 4222 | void ForbidInlineConstructor(); |
| 4223 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4224 | // For functions which only contains this property assignments this provides |
| 4225 | // access to the names for the properties assigned. |
| 4226 | DECL_ACCESSORS(this_property_assignments, Object) |
| 4227 | inline int this_property_assignments_count(); |
| 4228 | inline void set_this_property_assignments_count(int value); |
| 4229 | String* GetThisPropertyAssignmentName(int index); |
| 4230 | bool IsThisPropertyAssignmentArgument(int index); |
| 4231 | int GetThisPropertyAssignmentArgument(int index); |
| 4232 | Object* GetThisPropertyAssignmentConstant(int index); |
| 4233 | |
| 4234 | // [source code]: Source code for the function. |
| 4235 | bool HasSourceCode(); |
| 4236 | Object* GetSourceCode(); |
| 4237 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4238 | inline int opt_count(); |
| 4239 | inline void set_opt_count(int opt_count); |
| 4240 | |
| 4241 | // Source size of this function. |
| 4242 | int SourceSize(); |
| 4243 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4244 | // Calculate the instance size. |
| 4245 | int CalculateInstanceSize(); |
| 4246 | |
| 4247 | // Calculate the number of in-object properties. |
| 4248 | int CalculateInObjectProperties(); |
| 4249 | |
| 4250 | // Dispatched behavior. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4251 | // Set max_length to -1 for unlimited length. |
| 4252 | void SourceCodePrint(StringStream* accumulator, int max_length); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4253 | #ifdef OBJECT_PRINT |
| 4254 | inline void SharedFunctionInfoPrint() { |
| 4255 | SharedFunctionInfoPrint(stdout); |
| 4256 | } |
| 4257 | void SharedFunctionInfoPrint(FILE* out); |
| 4258 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4259 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4260 | void SharedFunctionInfoVerify(); |
| 4261 | #endif |
| 4262 | |
| 4263 | // Casting. |
| 4264 | static inline SharedFunctionInfo* cast(Object* obj); |
| 4265 | |
| 4266 | // Constants. |
| 4267 | static const int kDontAdaptArgumentsSentinel = -1; |
| 4268 | |
| 4269 | // Layout description. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4270 | // Pointer fields. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4271 | static const int kNameOffset = HeapObject::kHeaderSize; |
| 4272 | static const int kCodeOffset = kNameOffset + kPointerSize; |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 4273 | static const int kScopeInfoOffset = kCodeOffset + kPointerSize; |
| 4274 | static const int kConstructStubOffset = kScopeInfoOffset + kPointerSize; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4275 | static const int kInstanceClassNameOffset = |
| 4276 | kConstructStubOffset + kPointerSize; |
| 4277 | static const int kFunctionDataOffset = |
| 4278 | kInstanceClassNameOffset + kPointerSize; |
| 4279 | static const int kScriptOffset = kFunctionDataOffset + kPointerSize; |
| 4280 | static const int kDebugInfoOffset = kScriptOffset + kPointerSize; |
| 4281 | static const int kInferredNameOffset = kDebugInfoOffset + kPointerSize; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4282 | static const int kInitialMapOffset = |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4283 | kInferredNameOffset + kPointerSize; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4284 | static const int kThisPropertyAssignmentsOffset = |
| 4285 | kInitialMapOffset + kPointerSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4286 | static const int kDeoptCounterOffset = |
| 4287 | kThisPropertyAssignmentsOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4288 | #if V8_HOST_ARCH_32_BIT |
| 4289 | // Smi fields. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4290 | static const int kLengthOffset = |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4291 | kDeoptCounterOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4292 | static const int kFormalParameterCountOffset = kLengthOffset + kPointerSize; |
| 4293 | static const int kExpectedNofPropertiesOffset = |
| 4294 | kFormalParameterCountOffset + kPointerSize; |
| 4295 | static const int kNumLiteralsOffset = |
| 4296 | kExpectedNofPropertiesOffset + kPointerSize; |
| 4297 | static const int kStartPositionAndTypeOffset = |
| 4298 | kNumLiteralsOffset + kPointerSize; |
| 4299 | static const int kEndPositionOffset = |
| 4300 | kStartPositionAndTypeOffset + kPointerSize; |
| 4301 | static const int kFunctionTokenPositionOffset = |
| 4302 | kEndPositionOffset + kPointerSize; |
| 4303 | static const int kCompilerHintsOffset = |
| 4304 | kFunctionTokenPositionOffset + kPointerSize; |
| 4305 | static const int kThisPropertyAssignmentsCountOffset = |
| 4306 | kCompilerHintsOffset + kPointerSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4307 | static const int kOptCountOffset = |
| 4308 | kThisPropertyAssignmentsCountOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4309 | // Total size. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4310 | static const int kSize = kOptCountOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4311 | #else |
| 4312 | // The only reason to use smi fields instead of int fields |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4313 | // is to allow iteration without maps decoding during |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4314 | // garbage collections. |
| 4315 | // To avoid wasting space on 64-bit architectures we use |
| 4316 | // the following trick: we group integer fields into pairs |
| 4317 | // First integer in each pair is shifted left by 1. |
| 4318 | // By doing this we guarantee that LSB of each kPointerSize aligned |
| 4319 | // word is not set and thus this word cannot be treated as pointer |
| 4320 | // to HeapObject during old space traversal. |
| 4321 | static const int kLengthOffset = |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4322 | kDeoptCounterOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4323 | static const int kFormalParameterCountOffset = |
| 4324 | kLengthOffset + kIntSize; |
| 4325 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4326 | static const int kExpectedNofPropertiesOffset = |
| 4327 | kFormalParameterCountOffset + kIntSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4328 | static const int kNumLiteralsOffset = |
| 4329 | kExpectedNofPropertiesOffset + kIntSize; |
| 4330 | |
| 4331 | static const int kEndPositionOffset = |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4332 | kNumLiteralsOffset + kIntSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4333 | static const int kStartPositionAndTypeOffset = |
| 4334 | kEndPositionOffset + kIntSize; |
| 4335 | |
| 4336 | static const int kFunctionTokenPositionOffset = |
| 4337 | kStartPositionAndTypeOffset + kIntSize; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4338 | static const int kCompilerHintsOffset = |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4339 | kFunctionTokenPositionOffset + kIntSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4340 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4341 | static const int kThisPropertyAssignmentsCountOffset = |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4342 | kCompilerHintsOffset + kIntSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4343 | static const int kOptCountOffset = |
| 4344 | kThisPropertyAssignmentsCountOffset + kIntSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4345 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4346 | // Total size. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4347 | static const int kSize = kOptCountOffset + kIntSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4348 | |
| 4349 | #endif |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4350 | |
| 4351 | // The construction counter for inobject slack tracking is stored in the |
| 4352 | // most significant byte of compiler_hints which is otherwise unused. |
| 4353 | // Its offset depends on the endian-ness of the architecture. |
| 4354 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
| 4355 | static const int kConstructionCountOffset = kCompilerHintsOffset + 3; |
| 4356 | #elif __BYTE_ORDER == __BIG_ENDIAN |
| 4357 | static const int kConstructionCountOffset = kCompilerHintsOffset + 0; |
| 4358 | #else |
| 4359 | #error Unknown byte ordering |
| 4360 | #endif |
| 4361 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4362 | static const int kAlignedSize = POINTER_SIZE_ALIGN(kSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4363 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 4364 | typedef FixedBodyDescriptor<kNameOffset, |
| 4365 | kThisPropertyAssignmentsOffset + kPointerSize, |
| 4366 | kSize> BodyDescriptor; |
| 4367 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4368 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4369 | // Bit positions in start_position_and_type. |
| 4370 | // The source code start position is in the 30 most significant bits of |
| 4371 | // the start_position_and_type field. |
| 4372 | static const int kIsExpressionBit = 0; |
| 4373 | static const int kIsTopLevelBit = 1; |
| 4374 | static const int kStartPositionShift = 2; |
| 4375 | static const int kStartPositionMask = ~((1 << kStartPositionShift) - 1); |
| 4376 | |
| 4377 | // Bit positions in compiler_hints. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4378 | static const int kHasOnlySimpleThisPropertyAssignments = 0; |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 4379 | static const int kTryFullCodegen = 1; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 4380 | static const int kAllowLazyCompilation = 2; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4381 | static const int kLiveObjectsMayExist = 3; |
| 4382 | static const int kCodeAgeShift = 4; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4383 | static const int kCodeAgeMask = 0x7; |
| 4384 | static const int kOptimizationDisabled = 7; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 4385 | static const int kStrictModeFunction = 8; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4386 | |
| 4387 | DISALLOW_IMPLICIT_CONSTRUCTORS(SharedFunctionInfo); |
| 4388 | }; |
| 4389 | |
| 4390 | |
| 4391 | // JSFunction describes JavaScript functions. |
| 4392 | class JSFunction: public JSObject { |
| 4393 | public: |
| 4394 | // [prototype_or_initial_map]: |
| 4395 | DECL_ACCESSORS(prototype_or_initial_map, Object) |
| 4396 | |
| 4397 | // [shared_function_info]: The information about the function that |
| 4398 | // can be shared by instances. |
| 4399 | DECL_ACCESSORS(shared, SharedFunctionInfo) |
| 4400 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 4401 | inline SharedFunctionInfo* unchecked_shared(); |
| 4402 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4403 | // [context]: The context for this function. |
| 4404 | inline Context* context(); |
| 4405 | inline Object* unchecked_context(); |
| 4406 | inline void set_context(Object* context); |
| 4407 | |
| 4408 | // [code]: The generated code object for this function. Executed |
| 4409 | // when the function is invoked, e.g. foo() or new foo(). See |
| 4410 | // [[Call]] and [[Construct]] description in ECMA-262, section |
| 4411 | // 8.6.2, page 27. |
| 4412 | inline Code* code(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4413 | inline void set_code(Code* code); |
| 4414 | inline void ReplaceCode(Code* code); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4415 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 4416 | inline Code* unchecked_code(); |
| 4417 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4418 | // Tells whether this function is builtin. |
| 4419 | inline bool IsBuiltin(); |
| 4420 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4421 | // Tells whether or not the function needs arguments adaption. |
| 4422 | inline bool NeedsArgumentsAdaption(); |
| 4423 | |
| 4424 | // Tells whether or not this function has been optimized. |
| 4425 | inline bool IsOptimized(); |
| 4426 | |
| 4427 | // Mark this function for lazy recompilation. The function will be |
| 4428 | // recompiled the next time it is executed. |
| 4429 | void MarkForLazyRecompilation(); |
| 4430 | |
| 4431 | // Tells whether or not the function is already marked for lazy |
| 4432 | // recompilation. |
| 4433 | inline bool IsMarkedForLazyRecompilation(); |
| 4434 | |
| 4435 | // Compute a hash code for the source code of this function. |
| 4436 | uint32_t SourceHash(); |
| 4437 | |
| 4438 | // Check whether or not this function is inlineable. |
| 4439 | bool IsInlineable(); |
| 4440 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4441 | // [literals]: Fixed array holding the materialized literals. |
| 4442 | // |
| 4443 | // If the function contains object, regexp or array literals, the |
| 4444 | // literals array prefix contains the object, regexp, and array |
| 4445 | // function to be used when creating these literals. This is |
| 4446 | // necessary so that we do not dynamically lookup the object, regexp |
| 4447 | // or array functions. Performing a dynamic lookup, we might end up |
| 4448 | // using the functions from a new context that we should not have |
| 4449 | // access to. |
| 4450 | DECL_ACCESSORS(literals, FixedArray) |
| 4451 | |
| 4452 | // The initial map for an object created by this constructor. |
| 4453 | inline Map* initial_map(); |
| 4454 | inline void set_initial_map(Map* value); |
| 4455 | inline bool has_initial_map(); |
| 4456 | |
| 4457 | // Get and set the prototype property on a JSFunction. If the |
| 4458 | // function has an initial map the prototype is set on the initial |
| 4459 | // map. Otherwise, the prototype is put in the initial map field |
| 4460 | // until an initial map is needed. |
| 4461 | inline bool has_prototype(); |
| 4462 | inline bool has_instance_prototype(); |
| 4463 | inline Object* prototype(); |
| 4464 | inline Object* instance_prototype(); |
| 4465 | Object* SetInstancePrototype(Object* value); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 4466 | MUST_USE_RESULT MaybeObject* SetPrototype(Object* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4467 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4468 | // After prototype is removed, it will not be created when accessed, and |
| 4469 | // [[Construct]] from this function will not be allowed. |
| 4470 | Object* RemovePrototype(); |
| 4471 | inline bool should_have_prototype(); |
| 4472 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4473 | // Accessor for this function's initial map's [[class]] |
| 4474 | // property. This is primarily used by ECMA native functions. This |
| 4475 | // method sets the class_name field of this function's initial map |
| 4476 | // to a given value. It creates an initial map if this function does |
| 4477 | // not have one. Note that this method does not copy the initial map |
| 4478 | // if it has one already, but simply replaces it with the new value. |
| 4479 | // Instances created afterwards will have a map whose [[class]] is |
| 4480 | // set to 'value', but there is no guarantees on instances created |
| 4481 | // before. |
| 4482 | Object* SetInstanceClassName(String* name); |
| 4483 | |
| 4484 | // Returns if this function has been compiled to native code yet. |
| 4485 | inline bool is_compiled(); |
| 4486 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4487 | // [next_function_link]: Field for linking functions. This list is treated as |
| 4488 | // a weak list by the GC. |
| 4489 | DECL_ACCESSORS(next_function_link, Object) |
| 4490 | |
| 4491 | // Prints the name of the function using PrintF. |
| 4492 | inline void PrintName() { |
| 4493 | PrintName(stdout); |
| 4494 | } |
| 4495 | void PrintName(FILE* out); |
| 4496 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4497 | // Casting. |
| 4498 | static inline JSFunction* cast(Object* obj); |
| 4499 | |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 4500 | // Iterates the objects, including code objects indirectly referenced |
| 4501 | // through pointers to the first instruction in the code object. |
| 4502 | void JSFunctionIterateBody(int object_size, ObjectVisitor* v); |
| 4503 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4504 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4505 | #ifdef OBJECT_PRINT |
| 4506 | inline void JSFunctionPrint() { |
| 4507 | JSFunctionPrint(stdout); |
| 4508 | } |
| 4509 | void JSFunctionPrint(FILE* out); |
| 4510 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4511 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4512 | void JSFunctionVerify(); |
| 4513 | #endif |
| 4514 | |
| 4515 | // Returns the number of allocated literals. |
| 4516 | inline int NumberOfLiterals(); |
| 4517 | |
| 4518 | // Retrieve the global context from a function's literal array. |
| 4519 | static Context* GlobalContextFromLiterals(FixedArray* literals); |
| 4520 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4521 | // Layout descriptors. The last property (from kNonWeakFieldsEndOffset to |
| 4522 | // kSize) is weak and has special handling during garbage collection. |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 4523 | static const int kCodeEntryOffset = JSObject::kHeaderSize; |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 4524 | static const int kPrototypeOrInitialMapOffset = |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 4525 | kCodeEntryOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4526 | static const int kSharedFunctionInfoOffset = |
| 4527 | kPrototypeOrInitialMapOffset + kPointerSize; |
| 4528 | static const int kContextOffset = kSharedFunctionInfoOffset + kPointerSize; |
| 4529 | static const int kLiteralsOffset = kContextOffset + kPointerSize; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4530 | static const int kNonWeakFieldsEndOffset = kLiteralsOffset + kPointerSize; |
| 4531 | static const int kNextFunctionLinkOffset = kNonWeakFieldsEndOffset; |
| 4532 | static const int kSize = kNextFunctionLinkOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4533 | |
| 4534 | // Layout of the literals array. |
| 4535 | static const int kLiteralsPrefixSize = 1; |
| 4536 | static const int kLiteralGlobalContextIndex = 0; |
| 4537 | private: |
| 4538 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunction); |
| 4539 | }; |
| 4540 | |
| 4541 | |
| 4542 | // JSGlobalProxy's prototype must be a JSGlobalObject or null, |
| 4543 | // and the prototype is hidden. JSGlobalProxy always delegates |
| 4544 | // property accesses to its prototype if the prototype is not null. |
| 4545 | // |
| 4546 | // A JSGlobalProxy can be reinitialized which will preserve its identity. |
| 4547 | // |
| 4548 | // Accessing a JSGlobalProxy requires security check. |
| 4549 | |
| 4550 | class JSGlobalProxy : public JSObject { |
| 4551 | public: |
| 4552 | // [context]: the owner global context of this proxy object. |
| 4553 | // It is null value if this object is not used by any context. |
| 4554 | DECL_ACCESSORS(context, Object) |
| 4555 | |
| 4556 | // Casting. |
| 4557 | static inline JSGlobalProxy* cast(Object* obj); |
| 4558 | |
| 4559 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4560 | #ifdef OBJECT_PRINT |
| 4561 | inline void JSGlobalProxyPrint() { |
| 4562 | JSGlobalProxyPrint(stdout); |
| 4563 | } |
| 4564 | void JSGlobalProxyPrint(FILE* out); |
| 4565 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4566 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4567 | void JSGlobalProxyVerify(); |
| 4568 | #endif |
| 4569 | |
| 4570 | // Layout description. |
| 4571 | static const int kContextOffset = JSObject::kHeaderSize; |
| 4572 | static const int kSize = kContextOffset + kPointerSize; |
| 4573 | |
| 4574 | private: |
| 4575 | |
| 4576 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalProxy); |
| 4577 | }; |
| 4578 | |
| 4579 | |
| 4580 | // Forward declaration. |
| 4581 | class JSBuiltinsObject; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4582 | class JSGlobalPropertyCell; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4583 | |
| 4584 | // Common super class for JavaScript global objects and the special |
| 4585 | // builtins global objects. |
| 4586 | class GlobalObject: public JSObject { |
| 4587 | public: |
| 4588 | // [builtins]: the object holding the runtime routines written in JS. |
| 4589 | DECL_ACCESSORS(builtins, JSBuiltinsObject) |
| 4590 | |
| 4591 | // [global context]: the global context corresponding to this global object. |
| 4592 | DECL_ACCESSORS(global_context, Context) |
| 4593 | |
| 4594 | // [global receiver]: the global receiver object of the context |
| 4595 | DECL_ACCESSORS(global_receiver, JSObject) |
| 4596 | |
| 4597 | // Retrieve the property cell used to store a property. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4598 | JSGlobalPropertyCell* GetPropertyCell(LookupResult* result); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4599 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 4600 | // This is like GetProperty, but is used when you know the lookup won't fail |
| 4601 | // by throwing an exception. This is for the debug and builtins global |
| 4602 | // objects, where it is known which properties can be expected to be present |
| 4603 | // on the object. |
| 4604 | Object* GetPropertyNoExceptionThrown(String* key) { |
| 4605 | Object* answer = GetProperty(key)->ToObjectUnchecked(); |
| 4606 | return answer; |
| 4607 | } |
| 4608 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4609 | // 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] | 4610 | MUST_USE_RESULT MaybeObject* EnsurePropertyCell(String* name); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4611 | |
| 4612 | // Casting. |
| 4613 | static inline GlobalObject* cast(Object* obj); |
| 4614 | |
| 4615 | // Layout description. |
| 4616 | static const int kBuiltinsOffset = JSObject::kHeaderSize; |
| 4617 | static const int kGlobalContextOffset = kBuiltinsOffset + kPointerSize; |
| 4618 | static const int kGlobalReceiverOffset = kGlobalContextOffset + kPointerSize; |
| 4619 | static const int kHeaderSize = kGlobalReceiverOffset + kPointerSize; |
| 4620 | |
| 4621 | private: |
| 4622 | friend class AGCCVersionRequiresThisClassToHaveAFriendSoHereItIs; |
| 4623 | |
| 4624 | DISALLOW_IMPLICIT_CONSTRUCTORS(GlobalObject); |
| 4625 | }; |
| 4626 | |
| 4627 | |
| 4628 | // JavaScript global object. |
| 4629 | class JSGlobalObject: public GlobalObject { |
| 4630 | public: |
| 4631 | |
| 4632 | // Casting. |
| 4633 | static inline JSGlobalObject* cast(Object* obj); |
| 4634 | |
| 4635 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4636 | #ifdef OBJECT_PRINT |
| 4637 | inline void JSGlobalObjectPrint() { |
| 4638 | JSGlobalObjectPrint(stdout); |
| 4639 | } |
| 4640 | void JSGlobalObjectPrint(FILE* out); |
| 4641 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4642 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4643 | void JSGlobalObjectVerify(); |
| 4644 | #endif |
| 4645 | |
| 4646 | // Layout description. |
| 4647 | static const int kSize = GlobalObject::kHeaderSize; |
| 4648 | |
| 4649 | private: |
| 4650 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalObject); |
| 4651 | }; |
| 4652 | |
| 4653 | |
| 4654 | // Builtins global object which holds the runtime routines written in |
| 4655 | // JavaScript. |
| 4656 | class JSBuiltinsObject: public GlobalObject { |
| 4657 | public: |
| 4658 | // Accessors for the runtime routines written in JavaScript. |
| 4659 | inline Object* javascript_builtin(Builtins::JavaScript id); |
| 4660 | inline void set_javascript_builtin(Builtins::JavaScript id, Object* value); |
| 4661 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4662 | // Accessors for code of the runtime routines written in JavaScript. |
| 4663 | inline Code* javascript_builtin_code(Builtins::JavaScript id); |
| 4664 | inline void set_javascript_builtin_code(Builtins::JavaScript id, Code* value); |
| 4665 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4666 | // Casting. |
| 4667 | static inline JSBuiltinsObject* cast(Object* obj); |
| 4668 | |
| 4669 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4670 | #ifdef OBJECT_PRINT |
| 4671 | inline void JSBuiltinsObjectPrint() { |
| 4672 | JSBuiltinsObjectPrint(stdout); |
| 4673 | } |
| 4674 | void JSBuiltinsObjectPrint(FILE* out); |
| 4675 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4676 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4677 | void JSBuiltinsObjectVerify(); |
| 4678 | #endif |
| 4679 | |
| 4680 | // Layout description. The size of the builtins object includes |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4681 | // room for two pointers per runtime routine written in javascript |
| 4682 | // (function and code object). |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4683 | static const int kJSBuiltinsCount = Builtins::id_count; |
| 4684 | static const int kJSBuiltinsOffset = GlobalObject::kHeaderSize; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4685 | static const int kJSBuiltinsCodeOffset = |
| 4686 | GlobalObject::kHeaderSize + (kJSBuiltinsCount * kPointerSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4687 | static const int kSize = |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4688 | kJSBuiltinsCodeOffset + (kJSBuiltinsCount * kPointerSize); |
| 4689 | |
| 4690 | static int OffsetOfFunctionWithId(Builtins::JavaScript id) { |
| 4691 | return kJSBuiltinsOffset + id * kPointerSize; |
| 4692 | } |
| 4693 | |
| 4694 | static int OffsetOfCodeWithId(Builtins::JavaScript id) { |
| 4695 | return kJSBuiltinsCodeOffset + id * kPointerSize; |
| 4696 | } |
| 4697 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4698 | private: |
| 4699 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSBuiltinsObject); |
| 4700 | }; |
| 4701 | |
| 4702 | |
| 4703 | // Representation for JS Wrapper objects, String, Number, Boolean, Date, etc. |
| 4704 | class JSValue: public JSObject { |
| 4705 | public: |
| 4706 | // [value]: the object being wrapped. |
| 4707 | DECL_ACCESSORS(value, Object) |
| 4708 | |
| 4709 | // Casting. |
| 4710 | static inline JSValue* cast(Object* obj); |
| 4711 | |
| 4712 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4713 | #ifdef OBJECT_PRINT |
| 4714 | inline void JSValuePrint() { |
| 4715 | JSValuePrint(stdout); |
| 4716 | } |
| 4717 | void JSValuePrint(FILE* out); |
| 4718 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4719 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4720 | void JSValueVerify(); |
| 4721 | #endif |
| 4722 | |
| 4723 | // Layout description. |
| 4724 | static const int kValueOffset = JSObject::kHeaderSize; |
| 4725 | static const int kSize = kValueOffset + kPointerSize; |
| 4726 | |
| 4727 | private: |
| 4728 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSValue); |
| 4729 | }; |
| 4730 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 4731 | |
| 4732 | // Representation of message objects used for error reporting through |
| 4733 | // the API. The messages are formatted in JavaScript so this object is |
| 4734 | // a real JavaScript object. The information used for formatting the |
| 4735 | // error messages are not directly accessible from JavaScript to |
| 4736 | // prevent leaking information to user code called during error |
| 4737 | // formatting. |
| 4738 | class JSMessageObject: public JSObject { |
| 4739 | public: |
| 4740 | // [type]: the type of error message. |
| 4741 | DECL_ACCESSORS(type, String) |
| 4742 | |
| 4743 | // [arguments]: the arguments for formatting the error message. |
| 4744 | DECL_ACCESSORS(arguments, JSArray) |
| 4745 | |
| 4746 | // [script]: the script from which the error message originated. |
| 4747 | DECL_ACCESSORS(script, Object) |
| 4748 | |
| 4749 | // [stack_trace]: the stack trace for this error message. |
| 4750 | DECL_ACCESSORS(stack_trace, Object) |
| 4751 | |
| 4752 | // [stack_frames]: an array of stack frames for this error object. |
| 4753 | DECL_ACCESSORS(stack_frames, Object) |
| 4754 | |
| 4755 | // [start_position]: the start position in the script for the error message. |
| 4756 | inline int start_position(); |
| 4757 | inline void set_start_position(int value); |
| 4758 | |
| 4759 | // [end_position]: the end position in the script for the error message. |
| 4760 | inline int end_position(); |
| 4761 | inline void set_end_position(int value); |
| 4762 | |
| 4763 | // Casting. |
| 4764 | static inline JSMessageObject* cast(Object* obj); |
| 4765 | |
| 4766 | // Dispatched behavior. |
| 4767 | #ifdef OBJECT_PRINT |
| 4768 | inline void JSMessageObjectPrint() { |
| 4769 | JSMessageObjectPrint(stdout); |
| 4770 | } |
| 4771 | void JSMessageObjectPrint(FILE* out); |
| 4772 | #endif |
| 4773 | #ifdef DEBUG |
| 4774 | void JSMessageObjectVerify(); |
| 4775 | #endif |
| 4776 | |
| 4777 | // Layout description. |
| 4778 | static const int kTypeOffset = JSObject::kHeaderSize; |
| 4779 | static const int kArgumentsOffset = kTypeOffset + kPointerSize; |
| 4780 | static const int kScriptOffset = kArgumentsOffset + kPointerSize; |
| 4781 | static const int kStackTraceOffset = kScriptOffset + kPointerSize; |
| 4782 | static const int kStackFramesOffset = kStackTraceOffset + kPointerSize; |
| 4783 | static const int kStartPositionOffset = kStackFramesOffset + kPointerSize; |
| 4784 | static const int kEndPositionOffset = kStartPositionOffset + kPointerSize; |
| 4785 | static const int kSize = kEndPositionOffset + kPointerSize; |
| 4786 | |
| 4787 | typedef FixedBodyDescriptor<HeapObject::kMapOffset, |
| 4788 | kStackFramesOffset + kPointerSize, |
| 4789 | kSize> BodyDescriptor; |
| 4790 | }; |
| 4791 | |
| 4792 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4793 | // Regular expressions |
| 4794 | // The regular expression holds a single reference to a FixedArray in |
| 4795 | // the kDataOffset field. |
| 4796 | // The FixedArray contains the following data: |
| 4797 | // - tag : type of regexp implementation (not compiled yet, atom or irregexp) |
| 4798 | // - reference to the original source string |
| 4799 | // - reference to the original flag string |
| 4800 | // If it is an atom regexp |
| 4801 | // - a reference to a literal string to search for |
| 4802 | // If it is an irregexp regexp: |
| 4803 | // - a reference to code for ASCII inputs (bytecode or compiled). |
| 4804 | // - a reference to code for UC16 inputs (bytecode or compiled). |
| 4805 | // - max number of registers used by irregexp implementations. |
| 4806 | // - number of capture registers (output values) of the regexp. |
| 4807 | class JSRegExp: public JSObject { |
| 4808 | public: |
| 4809 | // Meaning of Type: |
| 4810 | // NOT_COMPILED: Initial value. No data has been stored in the JSRegExp yet. |
| 4811 | // ATOM: A simple string to match against using an indexOf operation. |
| 4812 | // IRREGEXP: Compiled with Irregexp. |
| 4813 | // IRREGEXP_NATIVE: Compiled to native code with Irregexp. |
| 4814 | enum Type { NOT_COMPILED, ATOM, IRREGEXP }; |
| 4815 | enum Flag { NONE = 0, GLOBAL = 1, IGNORE_CASE = 2, MULTILINE = 4 }; |
| 4816 | |
| 4817 | class Flags { |
| 4818 | public: |
| 4819 | explicit Flags(uint32_t value) : value_(value) { } |
| 4820 | bool is_global() { return (value_ & GLOBAL) != 0; } |
| 4821 | bool is_ignore_case() { return (value_ & IGNORE_CASE) != 0; } |
| 4822 | bool is_multiline() { return (value_ & MULTILINE) != 0; } |
| 4823 | uint32_t value() { return value_; } |
| 4824 | private: |
| 4825 | uint32_t value_; |
| 4826 | }; |
| 4827 | |
| 4828 | DECL_ACCESSORS(data, Object) |
| 4829 | |
| 4830 | inline Type TypeTag(); |
| 4831 | inline int CaptureCount(); |
| 4832 | inline Flags GetFlags(); |
| 4833 | inline String* Pattern(); |
| 4834 | inline Object* DataAt(int index); |
| 4835 | // Set implementation data after the object has been prepared. |
| 4836 | inline void SetDataAt(int index, Object* value); |
| 4837 | static int code_index(bool is_ascii) { |
| 4838 | if (is_ascii) { |
| 4839 | return kIrregexpASCIICodeIndex; |
| 4840 | } else { |
| 4841 | return kIrregexpUC16CodeIndex; |
| 4842 | } |
| 4843 | } |
| 4844 | |
| 4845 | static inline JSRegExp* cast(Object* obj); |
| 4846 | |
| 4847 | // Dispatched behavior. |
| 4848 | #ifdef DEBUG |
| 4849 | void JSRegExpVerify(); |
| 4850 | #endif |
| 4851 | |
| 4852 | static const int kDataOffset = JSObject::kHeaderSize; |
| 4853 | static const int kSize = kDataOffset + kPointerSize; |
| 4854 | |
| 4855 | // Indices in the data array. |
| 4856 | static const int kTagIndex = 0; |
| 4857 | static const int kSourceIndex = kTagIndex + 1; |
| 4858 | static const int kFlagsIndex = kSourceIndex + 1; |
| 4859 | static const int kDataIndex = kFlagsIndex + 1; |
| 4860 | // The data fields are used in different ways depending on the |
| 4861 | // value of the tag. |
| 4862 | // Atom regexps (literal strings). |
| 4863 | static const int kAtomPatternIndex = kDataIndex; |
| 4864 | |
| 4865 | static const int kAtomDataSize = kAtomPatternIndex + 1; |
| 4866 | |
| 4867 | // Irregexp compiled code or bytecode for ASCII. If compilation |
| 4868 | // fails, this fields hold an exception object that should be |
| 4869 | // thrown if the regexp is used again. |
| 4870 | static const int kIrregexpASCIICodeIndex = kDataIndex; |
| 4871 | // Irregexp compiled code or bytecode for UC16. If compilation |
| 4872 | // fails, this fields hold an exception object that should be |
| 4873 | // thrown if the regexp is used again. |
| 4874 | static const int kIrregexpUC16CodeIndex = kDataIndex + 1; |
| 4875 | // Maximal number of registers used by either ASCII or UC16. |
| 4876 | // Only used to check that there is enough stack space |
| 4877 | static const int kIrregexpMaxRegisterCountIndex = kDataIndex + 2; |
| 4878 | // Number of captures in the compiled regexp. |
| 4879 | static const int kIrregexpCaptureCountIndex = kDataIndex + 3; |
| 4880 | |
| 4881 | static const int kIrregexpDataSize = kIrregexpCaptureCountIndex + 1; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4882 | |
| 4883 | // Offsets directly into the data fixed array. |
| 4884 | static const int kDataTagOffset = |
| 4885 | FixedArray::kHeaderSize + kTagIndex * kPointerSize; |
| 4886 | static const int kDataAsciiCodeOffset = |
| 4887 | FixedArray::kHeaderSize + kIrregexpASCIICodeIndex * kPointerSize; |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 4888 | static const int kDataUC16CodeOffset = |
| 4889 | FixedArray::kHeaderSize + kIrregexpUC16CodeIndex * kPointerSize; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4890 | static const int kIrregexpCaptureCountOffset = |
| 4891 | FixedArray::kHeaderSize + kIrregexpCaptureCountIndex * kPointerSize; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4892 | |
| 4893 | // In-object fields. |
| 4894 | static const int kSourceFieldIndex = 0; |
| 4895 | static const int kGlobalFieldIndex = 1; |
| 4896 | static const int kIgnoreCaseFieldIndex = 2; |
| 4897 | static const int kMultilineFieldIndex = 3; |
| 4898 | static const int kLastIndexFieldIndex = 4; |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 4899 | static const int kInObjectFieldCount = 5; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4900 | }; |
| 4901 | |
| 4902 | |
| 4903 | class CompilationCacheShape { |
| 4904 | public: |
| 4905 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
| 4906 | return key->IsMatch(value); |
| 4907 | } |
| 4908 | |
| 4909 | static inline uint32_t Hash(HashTableKey* key) { |
| 4910 | return key->Hash(); |
| 4911 | } |
| 4912 | |
| 4913 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
| 4914 | return key->HashForObject(object); |
| 4915 | } |
| 4916 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 4917 | MUST_USE_RESULT static MaybeObject* AsObject(HashTableKey* key) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4918 | return key->AsObject(); |
| 4919 | } |
| 4920 | |
| 4921 | static const int kPrefixSize = 0; |
| 4922 | static const int kEntrySize = 2; |
| 4923 | }; |
| 4924 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 4925 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4926 | class CompilationCacheTable: public HashTable<CompilationCacheShape, |
| 4927 | HashTableKey*> { |
| 4928 | public: |
| 4929 | // Find cached value for a string key, otherwise return null. |
| 4930 | Object* Lookup(String* src); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 4931 | Object* LookupEval(String* src, Context* context, StrictModeFlag strict_mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4932 | Object* LookupRegExp(String* source, JSRegExp::Flags flags); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 4933 | MaybeObject* Put(String* src, Object* value); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame^] | 4934 | MaybeObject* PutEval(String* src, |
| 4935 | Context* context, |
| 4936 | SharedFunctionInfo* value); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 4937 | MaybeObject* PutRegExp(String* src, JSRegExp::Flags flags, FixedArray* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4938 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4939 | // Remove given value from cache. |
| 4940 | void Remove(Object* value); |
| 4941 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4942 | static inline CompilationCacheTable* cast(Object* obj); |
| 4943 | |
| 4944 | private: |
| 4945 | DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheTable); |
| 4946 | }; |
| 4947 | |
| 4948 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4949 | class CodeCache: public Struct { |
| 4950 | public: |
| 4951 | DECL_ACCESSORS(default_cache, FixedArray) |
| 4952 | DECL_ACCESSORS(normal_type_cache, Object) |
| 4953 | |
| 4954 | // Add the code object to the cache. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 4955 | MUST_USE_RESULT MaybeObject* Update(String* name, Code* code); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4956 | |
| 4957 | // Lookup code object in the cache. Returns code object if found and undefined |
| 4958 | // if not. |
| 4959 | Object* Lookup(String* name, Code::Flags flags); |
| 4960 | |
| 4961 | // Get the internal index of a code object in the cache. Returns -1 if the |
| 4962 | // code object is not in that cache. This index can be used to later call |
| 4963 | // RemoveByIndex. The cache cannot be modified between a call to GetIndex and |
| 4964 | // RemoveByIndex. |
| 4965 | int GetIndex(Object* name, Code* code); |
| 4966 | |
| 4967 | // Remove an object from the cache with the provided internal index. |
| 4968 | void RemoveByIndex(Object* name, Code* code, int index); |
| 4969 | |
| 4970 | static inline CodeCache* cast(Object* obj); |
| 4971 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4972 | #ifdef OBJECT_PRINT |
| 4973 | inline void CodeCachePrint() { |
| 4974 | CodeCachePrint(stdout); |
| 4975 | } |
| 4976 | void CodeCachePrint(FILE* out); |
| 4977 | #endif |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4978 | #ifdef DEBUG |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4979 | void CodeCacheVerify(); |
| 4980 | #endif |
| 4981 | |
| 4982 | static const int kDefaultCacheOffset = HeapObject::kHeaderSize; |
| 4983 | static const int kNormalTypeCacheOffset = |
| 4984 | kDefaultCacheOffset + kPointerSize; |
| 4985 | static const int kSize = kNormalTypeCacheOffset + kPointerSize; |
| 4986 | |
| 4987 | private: |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 4988 | MUST_USE_RESULT MaybeObject* UpdateDefaultCache(String* name, Code* code); |
| 4989 | MUST_USE_RESULT MaybeObject* UpdateNormalTypeCache(String* name, Code* code); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4990 | Object* LookupDefaultCache(String* name, Code::Flags flags); |
| 4991 | Object* LookupNormalTypeCache(String* name, Code::Flags flags); |
| 4992 | |
| 4993 | // Code cache layout of the default cache. Elements are alternating name and |
| 4994 | // code objects for non normal load/store/call IC's. |
| 4995 | static const int kCodeCacheEntrySize = 2; |
| 4996 | static const int kCodeCacheEntryNameOffset = 0; |
| 4997 | static const int kCodeCacheEntryCodeOffset = 1; |
| 4998 | |
| 4999 | DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCache); |
| 5000 | }; |
| 5001 | |
| 5002 | |
| 5003 | class CodeCacheHashTableShape { |
| 5004 | public: |
| 5005 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
| 5006 | return key->IsMatch(value); |
| 5007 | } |
| 5008 | |
| 5009 | static inline uint32_t Hash(HashTableKey* key) { |
| 5010 | return key->Hash(); |
| 5011 | } |
| 5012 | |
| 5013 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
| 5014 | return key->HashForObject(object); |
| 5015 | } |
| 5016 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 5017 | MUST_USE_RESULT static MaybeObject* AsObject(HashTableKey* key) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5018 | return key->AsObject(); |
| 5019 | } |
| 5020 | |
| 5021 | static const int kPrefixSize = 0; |
| 5022 | static const int kEntrySize = 2; |
| 5023 | }; |
| 5024 | |
| 5025 | |
| 5026 | class CodeCacheHashTable: public HashTable<CodeCacheHashTableShape, |
| 5027 | HashTableKey*> { |
| 5028 | public: |
| 5029 | Object* Lookup(String* name, Code::Flags flags); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 5030 | MUST_USE_RESULT MaybeObject* Put(String* name, Code* code); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5031 | |
| 5032 | int GetIndex(String* name, Code::Flags flags); |
| 5033 | void RemoveByIndex(int index); |
| 5034 | |
| 5035 | static inline CodeCacheHashTable* cast(Object* obj); |
| 5036 | |
| 5037 | // Initial size of the fixed array backing the hash table. |
| 5038 | static const int kInitialSize = 64; |
| 5039 | |
| 5040 | private: |
| 5041 | DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCacheHashTable); |
| 5042 | }; |
| 5043 | |
| 5044 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5045 | enum AllowNullsFlag {ALLOW_NULLS, DISALLOW_NULLS}; |
| 5046 | enum RobustnessFlag {ROBUST_STRING_TRAVERSAL, FAST_STRING_TRAVERSAL}; |
| 5047 | |
| 5048 | |
| 5049 | class StringHasher { |
| 5050 | public: |
| 5051 | inline StringHasher(int length); |
| 5052 | |
| 5053 | // Returns true if the hash of this string can be computed without |
| 5054 | // looking at the contents. |
| 5055 | inline bool has_trivial_hash(); |
| 5056 | |
| 5057 | // Add a character to the hash and update the array index calculation. |
| 5058 | inline void AddCharacter(uc32 c); |
| 5059 | |
| 5060 | // Adds a character to the hash but does not update the array index |
| 5061 | // calculation. This can only be called when it has been verified |
| 5062 | // that the input is not an array index. |
| 5063 | inline void AddCharacterNoIndex(uc32 c); |
| 5064 | |
| 5065 | // Returns the value to store in the hash field of a string with |
| 5066 | // the given length and contents. |
| 5067 | uint32_t GetHashField(); |
| 5068 | |
| 5069 | // Returns true if the characters seen so far make up a legal array |
| 5070 | // index. |
| 5071 | bool is_array_index() { return is_array_index_; } |
| 5072 | |
| 5073 | bool is_valid() { return is_valid_; } |
| 5074 | |
| 5075 | void invalidate() { is_valid_ = false; } |
| 5076 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5077 | // Calculated hash value for a string consisting of 1 to |
| 5078 | // String::kMaxArrayIndexSize digits with no leading zeros (except "0"). |
| 5079 | // value is represented decimal value. |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 5080 | static uint32_t MakeArrayIndexHash(uint32_t value, int length); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5081 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5082 | private: |
| 5083 | |
| 5084 | uint32_t array_index() { |
| 5085 | ASSERT(is_array_index()); |
| 5086 | return array_index_; |
| 5087 | } |
| 5088 | |
| 5089 | inline uint32_t GetHash(); |
| 5090 | |
| 5091 | int length_; |
| 5092 | uint32_t raw_running_hash_; |
| 5093 | uint32_t array_index_; |
| 5094 | bool is_array_index_; |
| 5095 | bool is_first_char_; |
| 5096 | bool is_valid_; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5097 | friend class TwoCharHashTableKey; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5098 | }; |
| 5099 | |
| 5100 | |
| 5101 | // The characteristics of a string are stored in its map. Retrieving these |
| 5102 | // few bits of information is moderately expensive, involving two memory |
| 5103 | // loads where the second is dependent on the first. To improve efficiency |
| 5104 | // the shape of the string is given its own class so that it can be retrieved |
| 5105 | // once and used for several string operations. A StringShape is small enough |
| 5106 | // to be passed by value and is immutable, but be aware that flattening a |
| 5107 | // string can potentially alter its shape. Also be aware that a GC caused by |
| 5108 | // something else can alter the shape of a string due to ConsString |
| 5109 | // shortcutting. Keeping these restrictions in mind has proven to be error- |
| 5110 | // prone and so we no longer put StringShapes in variables unless there is a |
| 5111 | // concrete performance benefit at that particular point in the code. |
| 5112 | class StringShape BASE_EMBEDDED { |
| 5113 | public: |
| 5114 | inline explicit StringShape(String* s); |
| 5115 | inline explicit StringShape(Map* s); |
| 5116 | inline explicit StringShape(InstanceType t); |
| 5117 | inline bool IsSequential(); |
| 5118 | inline bool IsExternal(); |
| 5119 | inline bool IsCons(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5120 | inline bool IsExternalAscii(); |
| 5121 | inline bool IsExternalTwoByte(); |
| 5122 | inline bool IsSequentialAscii(); |
| 5123 | inline bool IsSequentialTwoByte(); |
| 5124 | inline bool IsSymbol(); |
| 5125 | inline StringRepresentationTag representation_tag(); |
| 5126 | inline uint32_t full_representation_tag(); |
| 5127 | inline uint32_t size_tag(); |
| 5128 | #ifdef DEBUG |
| 5129 | inline uint32_t type() { return type_; } |
| 5130 | inline void invalidate() { valid_ = false; } |
| 5131 | inline bool valid() { return valid_; } |
| 5132 | #else |
| 5133 | inline void invalidate() { } |
| 5134 | #endif |
| 5135 | private: |
| 5136 | uint32_t type_; |
| 5137 | #ifdef DEBUG |
| 5138 | inline void set_valid() { valid_ = true; } |
| 5139 | bool valid_; |
| 5140 | #else |
| 5141 | inline void set_valid() { } |
| 5142 | #endif |
| 5143 | }; |
| 5144 | |
| 5145 | |
| 5146 | // The String abstract class captures JavaScript string values: |
| 5147 | // |
| 5148 | // Ecma-262: |
| 5149 | // 4.3.16 String Value |
| 5150 | // A string value is a member of the type String and is a finite |
| 5151 | // ordered sequence of zero or more 16-bit unsigned integer values. |
| 5152 | // |
| 5153 | // All string values have a length field. |
| 5154 | class String: public HeapObject { |
| 5155 | public: |
| 5156 | // Get and set the length of the string. |
| 5157 | inline int length(); |
| 5158 | inline void set_length(int value); |
| 5159 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5160 | // Get and set the hash field of the string. |
| 5161 | inline uint32_t hash_field(); |
| 5162 | inline void set_hash_field(uint32_t value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5163 | |
| 5164 | inline bool IsAsciiRepresentation(); |
| 5165 | inline bool IsTwoByteRepresentation(); |
| 5166 | |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 5167 | // Returns whether this string has ascii chars, i.e. all of them can |
| 5168 | // be ascii encoded. This might be the case even if the string is |
| 5169 | // two-byte. Such strings may appear when the embedder prefers |
| 5170 | // two-byte external representations even for ascii data. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5171 | // |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 5172 | // NOTE: this should be considered only a hint. False negatives are |
| 5173 | // possible. |
| 5174 | inline bool HasOnlyAsciiChars(); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5175 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5176 | // Get and set individual two byte chars in the string. |
| 5177 | inline void Set(int index, uint16_t value); |
| 5178 | // Get individual two byte char in the string. Repeated calls |
| 5179 | // to this method are not efficient unless the string is flat. |
| 5180 | inline uint16_t Get(int index); |
| 5181 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 5182 | // Try to flatten the string. Checks first inline to see if it is |
| 5183 | // necessary. Does nothing if the string is not a cons string. |
| 5184 | // Flattening allocates a sequential string with the same data as |
| 5185 | // the given string and mutates the cons string to a degenerate |
| 5186 | // form, where the first component is the new sequential string and |
| 5187 | // the second component is the empty string. If allocation fails, |
| 5188 | // this function returns a failure. If flattening succeeds, this |
| 5189 | // function returns the sequential string that is now the first |
| 5190 | // component of the cons string. |
| 5191 | // |
| 5192 | // Degenerate cons strings are handled specially by the garbage |
| 5193 | // collector (see IsShortcutCandidate). |
| 5194 | // |
| 5195 | // Use FlattenString from Handles.cc to flatten even in case an |
| 5196 | // allocation failure happens. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 5197 | inline MaybeObject* TryFlatten(PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5198 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 5199 | // Convenience function. Has exactly the same behavior as |
| 5200 | // TryFlatten(), except in the case of failure returns the original |
| 5201 | // string. |
| 5202 | inline String* TryFlattenGetString(PretenureFlag pretenure = NOT_TENURED); |
| 5203 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5204 | Vector<const char> ToAsciiVector(); |
| 5205 | Vector<const uc16> ToUC16Vector(); |
| 5206 | |
| 5207 | // Mark the string as an undetectable object. It only applies to |
| 5208 | // ascii and two byte string types. |
| 5209 | bool MarkAsUndetectable(); |
| 5210 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5211 | // Return a substring. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 5212 | MUST_USE_RESULT MaybeObject* SubString(int from, |
| 5213 | int to, |
| 5214 | PretenureFlag pretenure = NOT_TENURED); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5215 | |
| 5216 | // String equality operations. |
| 5217 | inline bool Equals(String* other); |
| 5218 | bool IsEqualTo(Vector<const char> str); |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 5219 | bool IsAsciiEqualTo(Vector<const char> str); |
| 5220 | bool IsTwoByteEqualTo(Vector<const uc16> str); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5221 | |
| 5222 | // Return a UTF8 representation of the string. The string is null |
| 5223 | // terminated but may optionally contain nulls. Length is returned |
| 5224 | // in length_output if length_output is not a null pointer The string |
| 5225 | // should be nearly flat, otherwise the performance of this method may |
| 5226 | // be very slow (quadratic in the length). Setting robustness_flag to |
| 5227 | // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it |
| 5228 | // handles unexpected data without causing assert failures and it does not |
| 5229 | // do any heap allocations. This is useful when printing stack traces. |
| 5230 | SmartPointer<char> ToCString(AllowNullsFlag allow_nulls, |
| 5231 | RobustnessFlag robustness_flag, |
| 5232 | int offset, |
| 5233 | int length, |
| 5234 | int* length_output = 0); |
| 5235 | SmartPointer<char> ToCString( |
| 5236 | AllowNullsFlag allow_nulls = DISALLOW_NULLS, |
| 5237 | RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL, |
| 5238 | int* length_output = 0); |
| 5239 | |
| 5240 | int Utf8Length(); |
| 5241 | |
| 5242 | // Return a 16 bit Unicode representation of the string. |
| 5243 | // The string should be nearly flat, otherwise the performance of |
| 5244 | // of this method may be very bad. Setting robustness_flag to |
| 5245 | // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it |
| 5246 | // handles unexpected data without causing assert failures and it does not |
| 5247 | // do any heap allocations. This is useful when printing stack traces. |
| 5248 | SmartPointer<uc16> ToWideCString( |
| 5249 | RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL); |
| 5250 | |
| 5251 | // Tells whether the hash code has been computed. |
| 5252 | inline bool HasHashCode(); |
| 5253 | |
| 5254 | // Returns a hash value used for the property table |
| 5255 | inline uint32_t Hash(); |
| 5256 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5257 | static uint32_t ComputeHashField(unibrow::CharacterStream* buffer, |
| 5258 | int length); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5259 | |
| 5260 | static bool ComputeArrayIndex(unibrow::CharacterStream* buffer, |
| 5261 | uint32_t* index, |
| 5262 | int length); |
| 5263 | |
| 5264 | // Externalization. |
| 5265 | bool MakeExternal(v8::String::ExternalStringResource* resource); |
| 5266 | bool MakeExternal(v8::String::ExternalAsciiStringResource* resource); |
| 5267 | |
| 5268 | // Conversion. |
| 5269 | inline bool AsArrayIndex(uint32_t* index); |
| 5270 | |
| 5271 | // Casting. |
| 5272 | static inline String* cast(Object* obj); |
| 5273 | |
| 5274 | void PrintOn(FILE* out); |
| 5275 | |
| 5276 | // For use during stack traces. Performs rudimentary sanity check. |
| 5277 | bool LooksValid(); |
| 5278 | |
| 5279 | // Dispatched behavior. |
| 5280 | void StringShortPrint(StringStream* accumulator); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5281 | #ifdef OBJECT_PRINT |
| 5282 | inline void StringPrint() { |
| 5283 | StringPrint(stdout); |
| 5284 | } |
| 5285 | void StringPrint(FILE* out); |
| 5286 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5287 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5288 | void StringVerify(); |
| 5289 | #endif |
| 5290 | inline bool IsFlat(); |
| 5291 | |
| 5292 | // Layout description. |
| 5293 | static const int kLengthOffset = HeapObject::kHeaderSize; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5294 | static const int kHashFieldOffset = kLengthOffset + kPointerSize; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 5295 | static const int kSize = kHashFieldOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5296 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5297 | // Maximum number of characters to consider when trying to convert a string |
| 5298 | // value into an array index. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5299 | static const int kMaxArrayIndexSize = 10; |
| 5300 | |
| 5301 | // Max ascii char code. |
| 5302 | static const int kMaxAsciiCharCode = unibrow::Utf8::kMaxOneByteChar; |
| 5303 | static const unsigned kMaxAsciiCharCodeU = unibrow::Utf8::kMaxOneByteChar; |
| 5304 | static const int kMaxUC16CharCode = 0xffff; |
| 5305 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5306 | // Minimum length for a cons string. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5307 | static const int kMinNonFlatLength = 13; |
| 5308 | |
| 5309 | // Mask constant for checking if a string has a computed hash code |
| 5310 | // and if it is an array index. The least significant bit indicates |
| 5311 | // whether a hash code has been computed. If the hash code has been |
| 5312 | // computed the 2nd bit tells whether the string can be used as an |
| 5313 | // array index. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 5314 | static const int kHashNotComputedMask = 1; |
| 5315 | static const int kIsNotArrayIndexMask = 1 << 1; |
| 5316 | static const int kNofHashBitFields = 2; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5317 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5318 | // Shift constant retrieving hash code from hash field. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 5319 | static const int kHashShift = kNofHashBitFields; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5320 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5321 | // Array index strings this short can keep their index in the hash |
| 5322 | // field. |
| 5323 | static const int kMaxCachedArrayIndexLength = 7; |
| 5324 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5325 | // For strings which are array indexes the hash value has the string length |
| 5326 | // mixed into the hash, mainly to avoid a hash value of zero which would be |
| 5327 | // 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] | 5328 | static const int kArrayIndexValueBits = 24; |
| 5329 | static const int kArrayIndexLengthBits = |
| 5330 | kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields; |
| 5331 | |
| 5332 | STATIC_CHECK((kArrayIndexLengthBits > 0)); |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 5333 | STATIC_CHECK(kMaxArrayIndexSize < (1 << kArrayIndexLengthBits)); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 5334 | |
| 5335 | static const int kArrayIndexHashLengthShift = |
| 5336 | kArrayIndexValueBits + kNofHashBitFields; |
| 5337 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5338 | static const int kArrayIndexHashMask = (1 << kArrayIndexHashLengthShift) - 1; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 5339 | |
| 5340 | static const int kArrayIndexValueMask = |
| 5341 | ((1 << kArrayIndexValueBits) - 1) << kHashShift; |
| 5342 | |
| 5343 | // Check that kMaxCachedArrayIndexLength + 1 is a power of two so we |
| 5344 | // could use a mask to test if the length of string is less than or equal to |
| 5345 | // kMaxCachedArrayIndexLength. |
| 5346 | STATIC_CHECK(IS_POWER_OF_TWO(kMaxCachedArrayIndexLength + 1)); |
| 5347 | |
| 5348 | static const int kContainsCachedArrayIndexMask = |
| 5349 | (~kMaxCachedArrayIndexLength << kArrayIndexHashLengthShift) | |
| 5350 | kIsNotArrayIndexMask; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5351 | |
| 5352 | // Value of empty hash field indicating that the hash is not computed. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 5353 | static const int kEmptyHashField = |
| 5354 | kIsNotArrayIndexMask | kHashNotComputedMask; |
| 5355 | |
| 5356 | // Value of hash field containing computed hash equal to zero. |
| 5357 | static const int kZeroHash = kIsNotArrayIndexMask; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5358 | |
| 5359 | // Maximal string length. |
| 5360 | static const int kMaxLength = (1 << (32 - 2)) - 1; |
| 5361 | |
| 5362 | // Max length for computing hash. For strings longer than this limit the |
| 5363 | // string length is used as the hash value. |
| 5364 | static const int kMaxHashCalcLength = 16383; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5365 | |
| 5366 | // Limit for truncation in short printing. |
| 5367 | static const int kMaxShortPrintLength = 1024; |
| 5368 | |
| 5369 | // Support for regular expressions. |
| 5370 | const uc16* GetTwoByteData(); |
| 5371 | const uc16* GetTwoByteData(unsigned start); |
| 5372 | |
| 5373 | // Support for StringInputBuffer |
| 5374 | static const unibrow::byte* ReadBlock(String* input, |
| 5375 | unibrow::byte* util_buffer, |
| 5376 | unsigned capacity, |
| 5377 | unsigned* remaining, |
| 5378 | unsigned* offset); |
| 5379 | static const unibrow::byte* ReadBlock(String** input, |
| 5380 | unibrow::byte* util_buffer, |
| 5381 | unsigned capacity, |
| 5382 | unsigned* remaining, |
| 5383 | unsigned* offset); |
| 5384 | |
| 5385 | // Helper function for flattening strings. |
| 5386 | template <typename sinkchar> |
| 5387 | static void WriteToFlat(String* source, |
| 5388 | sinkchar* sink, |
| 5389 | int from, |
| 5390 | int to); |
| 5391 | |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 5392 | static inline bool IsAscii(const char* chars, int length) { |
| 5393 | const char* limit = chars + length; |
| 5394 | #ifdef V8_HOST_CAN_READ_UNALIGNED |
| 5395 | ASSERT(kMaxAsciiCharCode == 0x7F); |
| 5396 | const uintptr_t non_ascii_mask = kUintptrAllBitsSet / 0xFF * 0x80; |
| 5397 | while (chars <= limit - sizeof(uintptr_t)) { |
| 5398 | if (*reinterpret_cast<const uintptr_t*>(chars) & non_ascii_mask) { |
| 5399 | return false; |
| 5400 | } |
| 5401 | chars += sizeof(uintptr_t); |
| 5402 | } |
| 5403 | #endif |
| 5404 | while (chars < limit) { |
| 5405 | if (static_cast<uint8_t>(*chars) > kMaxAsciiCharCodeU) return false; |
| 5406 | ++chars; |
| 5407 | } |
| 5408 | return true; |
| 5409 | } |
| 5410 | |
| 5411 | static inline bool IsAscii(const uc16* chars, int length) { |
| 5412 | const uc16* limit = chars + length; |
| 5413 | while (chars < limit) { |
| 5414 | if (*chars > kMaxAsciiCharCodeU) return false; |
| 5415 | ++chars; |
| 5416 | } |
| 5417 | return true; |
| 5418 | } |
| 5419 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5420 | protected: |
| 5421 | class ReadBlockBuffer { |
| 5422 | public: |
| 5423 | ReadBlockBuffer(unibrow::byte* util_buffer_, |
| 5424 | unsigned cursor_, |
| 5425 | unsigned capacity_, |
| 5426 | unsigned remaining_) : |
| 5427 | util_buffer(util_buffer_), |
| 5428 | cursor(cursor_), |
| 5429 | capacity(capacity_), |
| 5430 | remaining(remaining_) { |
| 5431 | } |
| 5432 | unibrow::byte* util_buffer; |
| 5433 | unsigned cursor; |
| 5434 | unsigned capacity; |
| 5435 | unsigned remaining; |
| 5436 | }; |
| 5437 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5438 | static inline const unibrow::byte* ReadBlock(String* input, |
| 5439 | ReadBlockBuffer* buffer, |
| 5440 | unsigned* offset, |
| 5441 | unsigned max_chars); |
| 5442 | static void ReadBlockIntoBuffer(String* input, |
| 5443 | ReadBlockBuffer* buffer, |
| 5444 | unsigned* offset_ptr, |
| 5445 | unsigned max_chars); |
| 5446 | |
| 5447 | private: |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 5448 | // Try to flatten the top level ConsString that is hiding behind this |
| 5449 | // string. This is a no-op unless the string is a ConsString. Flatten |
| 5450 | // mutates the ConsString and might return a failure. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 5451 | MUST_USE_RESULT MaybeObject* SlowTryFlatten(PretenureFlag pretenure); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 5452 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 5453 | static inline bool IsHashFieldComputed(uint32_t field); |
| 5454 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5455 | // Slow case of String::Equals. This implementation works on any strings |
| 5456 | // but it is most efficient on strings that are almost flat. |
| 5457 | bool SlowEquals(String* other); |
| 5458 | |
| 5459 | // Slow case of AsArrayIndex. |
| 5460 | bool SlowAsArrayIndex(uint32_t* index); |
| 5461 | |
| 5462 | // Compute and set the hash code. |
| 5463 | uint32_t ComputeAndSetHash(); |
| 5464 | |
| 5465 | DISALLOW_IMPLICIT_CONSTRUCTORS(String); |
| 5466 | }; |
| 5467 | |
| 5468 | |
| 5469 | // The SeqString abstract class captures sequential string values. |
| 5470 | class SeqString: public String { |
| 5471 | public: |
| 5472 | |
| 5473 | // Casting. |
| 5474 | static inline SeqString* cast(Object* obj); |
| 5475 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5476 | private: |
| 5477 | DISALLOW_IMPLICIT_CONSTRUCTORS(SeqString); |
| 5478 | }; |
| 5479 | |
| 5480 | |
| 5481 | // The AsciiString class captures sequential ascii string objects. |
| 5482 | // Each character in the AsciiString is an ascii character. |
| 5483 | class SeqAsciiString: public SeqString { |
| 5484 | public: |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 5485 | static const bool kHasAsciiEncoding = true; |
| 5486 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5487 | // Dispatched behavior. |
| 5488 | inline uint16_t SeqAsciiStringGet(int index); |
| 5489 | inline void SeqAsciiStringSet(int index, uint16_t value); |
| 5490 | |
| 5491 | // Get the address of the characters in this string. |
| 5492 | inline Address GetCharsAddress(); |
| 5493 | |
| 5494 | inline char* GetChars(); |
| 5495 | |
| 5496 | // Casting |
| 5497 | static inline SeqAsciiString* cast(Object* obj); |
| 5498 | |
| 5499 | // Garbage collection support. This method is called by the |
| 5500 | // garbage collector to compute the actual size of an AsciiString |
| 5501 | // instance. |
| 5502 | inline int SeqAsciiStringSize(InstanceType instance_type); |
| 5503 | |
| 5504 | // Computes the size for an AsciiString instance of a given length. |
| 5505 | static int SizeFor(int length) { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 5506 | return OBJECT_POINTER_ALIGN(kHeaderSize + length * kCharSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5507 | } |
| 5508 | |
| 5509 | // Layout description. |
| 5510 | static const int kHeaderSize = String::kSize; |
| 5511 | static const int kAlignedSize = POINTER_SIZE_ALIGN(kHeaderSize); |
| 5512 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 5513 | // Maximal memory usage for a single sequential ASCII string. |
| 5514 | static const int kMaxSize = 512 * MB; |
| 5515 | // Maximal length of a single sequential ASCII string. |
| 5516 | // Q.v. String::kMaxLength which is the maximal size of concatenated strings. |
| 5517 | static const int kMaxLength = (kMaxSize - kHeaderSize); |
| 5518 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5519 | // Support for StringInputBuffer. |
| 5520 | inline void SeqAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 5521 | unsigned* offset, |
| 5522 | unsigned chars); |
| 5523 | inline const unibrow::byte* SeqAsciiStringReadBlock(unsigned* remaining, |
| 5524 | unsigned* offset, |
| 5525 | unsigned chars); |
| 5526 | |
| 5527 | private: |
| 5528 | DISALLOW_IMPLICIT_CONSTRUCTORS(SeqAsciiString); |
| 5529 | }; |
| 5530 | |
| 5531 | |
| 5532 | // The TwoByteString class captures sequential unicode string objects. |
| 5533 | // Each character in the TwoByteString is a two-byte uint16_t. |
| 5534 | class SeqTwoByteString: public SeqString { |
| 5535 | public: |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 5536 | static const bool kHasAsciiEncoding = false; |
| 5537 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5538 | // Dispatched behavior. |
| 5539 | inline uint16_t SeqTwoByteStringGet(int index); |
| 5540 | inline void SeqTwoByteStringSet(int index, uint16_t value); |
| 5541 | |
| 5542 | // Get the address of the characters in this string. |
| 5543 | inline Address GetCharsAddress(); |
| 5544 | |
| 5545 | inline uc16* GetChars(); |
| 5546 | |
| 5547 | // For regexp code. |
| 5548 | const uint16_t* SeqTwoByteStringGetData(unsigned start); |
| 5549 | |
| 5550 | // Casting |
| 5551 | static inline SeqTwoByteString* cast(Object* obj); |
| 5552 | |
| 5553 | // Garbage collection support. This method is called by the |
| 5554 | // garbage collector to compute the actual size of a TwoByteString |
| 5555 | // instance. |
| 5556 | inline int SeqTwoByteStringSize(InstanceType instance_type); |
| 5557 | |
| 5558 | // Computes the size for a TwoByteString instance of a given length. |
| 5559 | static int SizeFor(int length) { |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 5560 | return OBJECT_POINTER_ALIGN(kHeaderSize + length * kShortSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5561 | } |
| 5562 | |
| 5563 | // Layout description. |
| 5564 | static const int kHeaderSize = String::kSize; |
| 5565 | static const int kAlignedSize = POINTER_SIZE_ALIGN(kHeaderSize); |
| 5566 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 5567 | // Maximal memory usage for a single sequential two-byte string. |
| 5568 | static const int kMaxSize = 512 * MB; |
| 5569 | // Maximal length of a single sequential two-byte string. |
| 5570 | // Q.v. String::kMaxLength which is the maximal size of concatenated strings. |
| 5571 | static const int kMaxLength = (kMaxSize - kHeaderSize) / sizeof(uint16_t); |
| 5572 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5573 | // Support for StringInputBuffer. |
| 5574 | inline void SeqTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 5575 | unsigned* offset_ptr, |
| 5576 | unsigned chars); |
| 5577 | |
| 5578 | private: |
| 5579 | DISALLOW_IMPLICIT_CONSTRUCTORS(SeqTwoByteString); |
| 5580 | }; |
| 5581 | |
| 5582 | |
| 5583 | // The ConsString class describes string values built by using the |
| 5584 | // addition operator on strings. A ConsString is a pair where the |
| 5585 | // first and second components are pointers to other string values. |
| 5586 | // One or both components of a ConsString can be pointers to other |
| 5587 | // ConsStrings, creating a binary tree of ConsStrings where the leaves |
| 5588 | // are non-ConsString string values. The string value represented by |
| 5589 | // a ConsString can be obtained by concatenating the leaf string |
| 5590 | // values in a left-to-right depth-first traversal of the tree. |
| 5591 | class ConsString: public String { |
| 5592 | public: |
| 5593 | // First string of the cons cell. |
| 5594 | inline String* first(); |
| 5595 | // Doesn't check that the result is a string, even in debug mode. This is |
| 5596 | // useful during GC where the mark bits confuse the checks. |
| 5597 | inline Object* unchecked_first(); |
| 5598 | inline void set_first(String* first, |
| 5599 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
| 5600 | |
| 5601 | // Second string of the cons cell. |
| 5602 | inline String* second(); |
| 5603 | // Doesn't check that the result is a string, even in debug mode. This is |
| 5604 | // useful during GC where the mark bits confuse the checks. |
| 5605 | inline Object* unchecked_second(); |
| 5606 | inline void set_second(String* second, |
| 5607 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
| 5608 | |
| 5609 | // Dispatched behavior. |
| 5610 | uint16_t ConsStringGet(int index); |
| 5611 | |
| 5612 | // Casting. |
| 5613 | static inline ConsString* cast(Object* obj); |
| 5614 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5615 | // Layout description. |
| 5616 | static const int kFirstOffset = POINTER_SIZE_ALIGN(String::kSize); |
| 5617 | static const int kSecondOffset = kFirstOffset + kPointerSize; |
| 5618 | static const int kSize = kSecondOffset + kPointerSize; |
| 5619 | |
| 5620 | // Support for StringInputBuffer. |
| 5621 | inline const unibrow::byte* ConsStringReadBlock(ReadBlockBuffer* buffer, |
| 5622 | unsigned* offset_ptr, |
| 5623 | unsigned chars); |
| 5624 | inline void ConsStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 5625 | unsigned* offset_ptr, |
| 5626 | unsigned chars); |
| 5627 | |
| 5628 | // Minimum length for a cons string. |
| 5629 | static const int kMinLength = 13; |
| 5630 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 5631 | typedef FixedBodyDescriptor<kFirstOffset, kSecondOffset + kPointerSize, kSize> |
| 5632 | BodyDescriptor; |
| 5633 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5634 | private: |
| 5635 | DISALLOW_IMPLICIT_CONSTRUCTORS(ConsString); |
| 5636 | }; |
| 5637 | |
| 5638 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5639 | // The ExternalString class describes string values that are backed by |
| 5640 | // a string resource that lies outside the V8 heap. ExternalStrings |
| 5641 | // consist of the length field common to all strings, a pointer to the |
| 5642 | // external resource. It is important to ensure (externally) that the |
| 5643 | // resource is not deallocated while the ExternalString is live in the |
| 5644 | // V8 heap. |
| 5645 | // |
| 5646 | // The API expects that all ExternalStrings are created through the |
| 5647 | // API. Therefore, ExternalStrings should not be used internally. |
| 5648 | class ExternalString: public String { |
| 5649 | public: |
| 5650 | // Casting |
| 5651 | static inline ExternalString* cast(Object* obj); |
| 5652 | |
| 5653 | // Layout description. |
| 5654 | static const int kResourceOffset = POINTER_SIZE_ALIGN(String::kSize); |
| 5655 | static const int kSize = kResourceOffset + kPointerSize; |
| 5656 | |
| 5657 | STATIC_CHECK(kResourceOffset == Internals::kStringResourceOffset); |
| 5658 | |
| 5659 | private: |
| 5660 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalString); |
| 5661 | }; |
| 5662 | |
| 5663 | |
| 5664 | // The ExternalAsciiString class is an external string backed by an |
| 5665 | // ASCII string. |
| 5666 | class ExternalAsciiString: public ExternalString { |
| 5667 | public: |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 5668 | static const bool kHasAsciiEncoding = true; |
| 5669 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5670 | typedef v8::String::ExternalAsciiStringResource Resource; |
| 5671 | |
| 5672 | // The underlying resource. |
| 5673 | inline Resource* resource(); |
| 5674 | inline void set_resource(Resource* buffer); |
| 5675 | |
| 5676 | // Dispatched behavior. |
| 5677 | uint16_t ExternalAsciiStringGet(int index); |
| 5678 | |
| 5679 | // Casting. |
| 5680 | static inline ExternalAsciiString* cast(Object* obj); |
| 5681 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5682 | // Garbage collection support. |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 5683 | inline void ExternalAsciiStringIterateBody(ObjectVisitor* v); |
| 5684 | |
| 5685 | template<typename StaticVisitor> |
| 5686 | inline void ExternalAsciiStringIterateBody(); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5687 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5688 | // Support for StringInputBuffer. |
| 5689 | const unibrow::byte* ExternalAsciiStringReadBlock(unsigned* remaining, |
| 5690 | unsigned* offset, |
| 5691 | unsigned chars); |
| 5692 | inline void ExternalAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 5693 | unsigned* offset, |
| 5694 | unsigned chars); |
| 5695 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5696 | private: |
| 5697 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalAsciiString); |
| 5698 | }; |
| 5699 | |
| 5700 | |
| 5701 | // The ExternalTwoByteString class is an external string backed by a UTF-16 |
| 5702 | // encoded string. |
| 5703 | class ExternalTwoByteString: public ExternalString { |
| 5704 | public: |
Leon Clarke | ac95265 | 2010-07-15 11:15:24 +0100 | [diff] [blame] | 5705 | static const bool kHasAsciiEncoding = false; |
| 5706 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5707 | typedef v8::String::ExternalStringResource Resource; |
| 5708 | |
| 5709 | // The underlying string resource. |
| 5710 | inline Resource* resource(); |
| 5711 | inline void set_resource(Resource* buffer); |
| 5712 | |
| 5713 | // Dispatched behavior. |
| 5714 | uint16_t ExternalTwoByteStringGet(int index); |
| 5715 | |
| 5716 | // For regexp code. |
| 5717 | const uint16_t* ExternalTwoByteStringGetData(unsigned start); |
| 5718 | |
| 5719 | // Casting. |
| 5720 | static inline ExternalTwoByteString* cast(Object* obj); |
| 5721 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5722 | // Garbage collection support. |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 5723 | inline void ExternalTwoByteStringIterateBody(ObjectVisitor* v); |
| 5724 | |
| 5725 | template<typename StaticVisitor> |
| 5726 | inline void ExternalTwoByteStringIterateBody(); |
| 5727 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5728 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5729 | // Support for StringInputBuffer. |
| 5730 | void ExternalTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 5731 | unsigned* offset_ptr, |
| 5732 | unsigned chars); |
| 5733 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5734 | private: |
| 5735 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalTwoByteString); |
| 5736 | }; |
| 5737 | |
| 5738 | |
| 5739 | // Utility superclass for stack-allocated objects that must be updated |
| 5740 | // on gc. It provides two ways for the gc to update instances, either |
| 5741 | // iterating or updating after gc. |
| 5742 | class Relocatable BASE_EMBEDDED { |
| 5743 | public: |
| 5744 | inline Relocatable() : prev_(top_) { top_ = this; } |
| 5745 | virtual ~Relocatable() { |
| 5746 | ASSERT_EQ(top_, this); |
| 5747 | top_ = prev_; |
| 5748 | } |
| 5749 | virtual void IterateInstance(ObjectVisitor* v) { } |
| 5750 | virtual void PostGarbageCollection() { } |
| 5751 | |
| 5752 | static void PostGarbageCollectionProcessing(); |
| 5753 | static int ArchiveSpacePerThread(); |
| 5754 | static char* ArchiveState(char* to); |
| 5755 | static char* RestoreState(char* from); |
| 5756 | static void Iterate(ObjectVisitor* v); |
| 5757 | static void Iterate(ObjectVisitor* v, Relocatable* top); |
| 5758 | static char* Iterate(ObjectVisitor* v, char* t); |
| 5759 | private: |
| 5760 | static Relocatable* top_; |
| 5761 | Relocatable* prev_; |
| 5762 | }; |
| 5763 | |
| 5764 | |
| 5765 | // A flat string reader provides random access to the contents of a |
| 5766 | // string independent of the character width of the string. The handle |
| 5767 | // must be valid as long as the reader is being used. |
| 5768 | class FlatStringReader : public Relocatable { |
| 5769 | public: |
| 5770 | explicit FlatStringReader(Handle<String> str); |
| 5771 | explicit FlatStringReader(Vector<const char> input); |
| 5772 | void PostGarbageCollection(); |
| 5773 | inline uc32 Get(int index); |
| 5774 | int length() { return length_; } |
| 5775 | private: |
| 5776 | String** str_; |
| 5777 | bool is_ascii_; |
| 5778 | int length_; |
| 5779 | const void* start_; |
| 5780 | }; |
| 5781 | |
| 5782 | |
| 5783 | // Note that StringInputBuffers are not valid across a GC! To fix this |
| 5784 | // it would have to store a String Handle instead of a String* and |
| 5785 | // AsciiStringReadBlock would have to be modified to use memcpy. |
| 5786 | // |
| 5787 | // StringInputBuffer is able to traverse any string regardless of how |
| 5788 | // deeply nested a sequence of ConsStrings it is made of. However, |
| 5789 | // performance will be better if deep strings are flattened before they |
| 5790 | // are traversed. Since flattening requires memory allocation this is |
| 5791 | // not always desirable, however (esp. in debugging situations). |
| 5792 | class StringInputBuffer: public unibrow::InputBuffer<String, String*, 1024> { |
| 5793 | public: |
| 5794 | virtual void Seek(unsigned pos); |
| 5795 | inline StringInputBuffer(): unibrow::InputBuffer<String, String*, 1024>() {} |
| 5796 | inline StringInputBuffer(String* backing): |
| 5797 | unibrow::InputBuffer<String, String*, 1024>(backing) {} |
| 5798 | }; |
| 5799 | |
| 5800 | |
| 5801 | class SafeStringInputBuffer |
| 5802 | : public unibrow::InputBuffer<String, String**, 256> { |
| 5803 | public: |
| 5804 | virtual void Seek(unsigned pos); |
| 5805 | inline SafeStringInputBuffer() |
| 5806 | : unibrow::InputBuffer<String, String**, 256>() {} |
| 5807 | inline SafeStringInputBuffer(String** backing) |
| 5808 | : unibrow::InputBuffer<String, String**, 256>(backing) {} |
| 5809 | }; |
| 5810 | |
| 5811 | |
| 5812 | template <typename T> |
| 5813 | class VectorIterator { |
| 5814 | public: |
| 5815 | VectorIterator(T* d, int l) : data_(Vector<const T>(d, l)), index_(0) { } |
| 5816 | explicit VectorIterator(Vector<const T> data) : data_(data), index_(0) { } |
| 5817 | T GetNext() { return data_[index_++]; } |
| 5818 | bool has_more() { return index_ < data_.length(); } |
| 5819 | private: |
| 5820 | Vector<const T> data_; |
| 5821 | int index_; |
| 5822 | }; |
| 5823 | |
| 5824 | |
| 5825 | // The Oddball describes objects null, undefined, true, and false. |
| 5826 | class Oddball: public HeapObject { |
| 5827 | public: |
| 5828 | // [to_string]: Cached to_string computed at startup. |
| 5829 | DECL_ACCESSORS(to_string, String) |
| 5830 | |
| 5831 | // [to_number]: Cached to_number computed at startup. |
| 5832 | DECL_ACCESSORS(to_number, Object) |
| 5833 | |
| 5834 | // Casting. |
| 5835 | static inline Oddball* cast(Object* obj); |
| 5836 | |
| 5837 | // Dispatched behavior. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5838 | #ifdef DEBUG |
| 5839 | void OddballVerify(); |
| 5840 | #endif |
| 5841 | |
| 5842 | // Initialize the fields. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 5843 | MUST_USE_RESULT MaybeObject* Initialize(const char* to_string, |
| 5844 | Object* to_number); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5845 | |
| 5846 | // Layout description. |
| 5847 | static const int kToStringOffset = HeapObject::kHeaderSize; |
| 5848 | static const int kToNumberOffset = kToStringOffset + kPointerSize; |
| 5849 | static const int kSize = kToNumberOffset + kPointerSize; |
| 5850 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 5851 | typedef FixedBodyDescriptor<kToStringOffset, |
| 5852 | kToNumberOffset + kPointerSize, |
| 5853 | kSize> BodyDescriptor; |
| 5854 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5855 | private: |
| 5856 | DISALLOW_IMPLICIT_CONSTRUCTORS(Oddball); |
| 5857 | }; |
| 5858 | |
| 5859 | |
| 5860 | class JSGlobalPropertyCell: public HeapObject { |
| 5861 | public: |
| 5862 | // [value]: value of the global property. |
| 5863 | DECL_ACCESSORS(value, Object) |
| 5864 | |
| 5865 | // Casting. |
| 5866 | static inline JSGlobalPropertyCell* cast(Object* obj); |
| 5867 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5868 | #ifdef DEBUG |
| 5869 | void JSGlobalPropertyCellVerify(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5870 | #endif |
| 5871 | #ifdef OBJECT_PRINT |
| 5872 | inline void JSGlobalPropertyCellPrint() { |
| 5873 | JSGlobalPropertyCellPrint(stdout); |
| 5874 | } |
| 5875 | void JSGlobalPropertyCellPrint(FILE* out); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5876 | #endif |
| 5877 | |
| 5878 | // Layout description. |
| 5879 | static const int kValueOffset = HeapObject::kHeaderSize; |
| 5880 | static const int kSize = kValueOffset + kPointerSize; |
| 5881 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 5882 | typedef FixedBodyDescriptor<kValueOffset, |
| 5883 | kValueOffset + kPointerSize, |
| 5884 | kSize> BodyDescriptor; |
| 5885 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5886 | private: |
| 5887 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalPropertyCell); |
| 5888 | }; |
| 5889 | |
| 5890 | |
| 5891 | |
| 5892 | // Proxy describes objects pointing from JavaScript to C structures. |
| 5893 | // Since they cannot contain references to JS HeapObjects they can be |
| 5894 | // placed in old_data_space. |
| 5895 | class Proxy: public HeapObject { |
| 5896 | public: |
| 5897 | // [proxy]: field containing the address. |
| 5898 | inline Address proxy(); |
| 5899 | inline void set_proxy(Address value); |
| 5900 | |
| 5901 | // Casting. |
| 5902 | static inline Proxy* cast(Object* obj); |
| 5903 | |
| 5904 | // Dispatched behavior. |
| 5905 | inline void ProxyIterateBody(ObjectVisitor* v); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 5906 | |
| 5907 | template<typename StaticVisitor> |
| 5908 | inline void ProxyIterateBody(); |
| 5909 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5910 | #ifdef OBJECT_PRINT |
| 5911 | inline void ProxyPrint() { |
| 5912 | ProxyPrint(stdout); |
| 5913 | } |
| 5914 | void ProxyPrint(FILE* out); |
| 5915 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5916 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5917 | void ProxyVerify(); |
| 5918 | #endif |
| 5919 | |
| 5920 | // Layout description. |
| 5921 | |
| 5922 | static const int kProxyOffset = HeapObject::kHeaderSize; |
| 5923 | static const int kSize = kProxyOffset + kPointerSize; |
| 5924 | |
| 5925 | STATIC_CHECK(kProxyOffset == Internals::kProxyProxyOffset); |
| 5926 | |
| 5927 | private: |
| 5928 | DISALLOW_IMPLICIT_CONSTRUCTORS(Proxy); |
| 5929 | }; |
| 5930 | |
| 5931 | |
| 5932 | // The JSArray describes JavaScript Arrays |
| 5933 | // Such an array can be in one of two modes: |
| 5934 | // - fast, backing storage is a FixedArray and length <= elements.length(); |
| 5935 | // Please note: push and pop can be used to grow and shrink the array. |
| 5936 | // - slow, backing storage is a HashTable with numbers as keys. |
| 5937 | class JSArray: public JSObject { |
| 5938 | public: |
| 5939 | // [length]: The length property. |
| 5940 | DECL_ACCESSORS(length, Object) |
| 5941 | |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 5942 | // Overload the length setter to skip write barrier when the length |
| 5943 | // is set to a smi. This matches the set function on FixedArray. |
| 5944 | inline void set_length(Smi* length); |
| 5945 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 5946 | MUST_USE_RESULT MaybeObject* JSArrayUpdateLengthFromIndex(uint32_t index, |
| 5947 | Object* value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5948 | |
| 5949 | // Initialize the array with the given capacity. The function may |
| 5950 | // fail due to out-of-memory situations, but only if the requested |
| 5951 | // capacity is non-zero. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 5952 | MUST_USE_RESULT MaybeObject* Initialize(int capacity); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5953 | |
| 5954 | // Set the content of the array to the content of storage. |
| 5955 | inline void SetContent(FixedArray* storage); |
| 5956 | |
| 5957 | // Casting. |
| 5958 | static inline JSArray* cast(Object* obj); |
| 5959 | |
| 5960 | // Uses handles. Ensures that the fixed array backing the JSArray has at |
| 5961 | // least the stated size. |
| 5962 | inline void EnsureSize(int minimum_size_of_backing_fixed_array); |
| 5963 | |
| 5964 | // Dispatched behavior. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 5965 | #ifdef OBJECT_PRINT |
| 5966 | inline void JSArrayPrint() { |
| 5967 | JSArrayPrint(stdout); |
| 5968 | } |
| 5969 | void JSArrayPrint(FILE* out); |
| 5970 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5971 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 5972 | void JSArrayVerify(); |
| 5973 | #endif |
| 5974 | |
| 5975 | // Number of element slots to pre-allocate for an empty array. |
| 5976 | static const int kPreallocatedArrayElements = 4; |
| 5977 | |
| 5978 | // Layout description. |
| 5979 | static const int kLengthOffset = JSObject::kHeaderSize; |
| 5980 | static const int kSize = kLengthOffset + kPointerSize; |
| 5981 | |
| 5982 | private: |
| 5983 | // Expand the fixed array backing of a fast-case JSArray to at least |
| 5984 | // the requested size. |
| 5985 | void Expand(int minimum_size_of_backing_fixed_array); |
| 5986 | |
| 5987 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSArray); |
| 5988 | }; |
| 5989 | |
| 5990 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 5991 | // JSRegExpResult is just a JSArray with a specific initial map. |
| 5992 | // This initial map adds in-object properties for "index" and "input" |
| 5993 | // properties, as assigned by RegExp.prototype.exec, which allows |
| 5994 | // faster creation of RegExp exec results. |
| 5995 | // This class just holds constants used when creating the result. |
| 5996 | // After creation the result must be treated as a JSArray in all regards. |
| 5997 | class JSRegExpResult: public JSArray { |
| 5998 | public: |
| 5999 | // Offsets of object fields. |
| 6000 | static const int kIndexOffset = JSArray::kSize; |
| 6001 | static const int kInputOffset = kIndexOffset + kPointerSize; |
| 6002 | static const int kSize = kInputOffset + kPointerSize; |
| 6003 | // Indices of in-object properties. |
| 6004 | static const int kIndexIndex = 0; |
| 6005 | static const int kInputIndex = 1; |
| 6006 | private: |
| 6007 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSRegExpResult); |
| 6008 | }; |
| 6009 | |
| 6010 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6011 | // An accessor must have a getter, but can have no setter. |
| 6012 | // |
| 6013 | // When setting a property, V8 searches accessors in prototypes. |
| 6014 | // If an accessor was found and it does not have a setter, |
| 6015 | // the request is ignored. |
| 6016 | // |
| 6017 | // If the accessor in the prototype has the READ_ONLY property attribute, then |
| 6018 | // a new value is added to the local object when the property is set. |
| 6019 | // This shadows the accessor in the prototype. |
| 6020 | class AccessorInfo: public Struct { |
| 6021 | public: |
| 6022 | DECL_ACCESSORS(getter, Object) |
| 6023 | DECL_ACCESSORS(setter, Object) |
| 6024 | DECL_ACCESSORS(data, Object) |
| 6025 | DECL_ACCESSORS(name, Object) |
| 6026 | DECL_ACCESSORS(flag, Smi) |
| 6027 | |
| 6028 | inline bool all_can_read(); |
| 6029 | inline void set_all_can_read(bool value); |
| 6030 | |
| 6031 | inline bool all_can_write(); |
| 6032 | inline void set_all_can_write(bool value); |
| 6033 | |
| 6034 | inline bool prohibits_overwriting(); |
| 6035 | inline void set_prohibits_overwriting(bool value); |
| 6036 | |
| 6037 | inline PropertyAttributes property_attributes(); |
| 6038 | inline void set_property_attributes(PropertyAttributes attributes); |
| 6039 | |
| 6040 | static inline AccessorInfo* cast(Object* obj); |
| 6041 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6042 | #ifdef OBJECT_PRINT |
| 6043 | inline void AccessorInfoPrint() { |
| 6044 | AccessorInfoPrint(stdout); |
| 6045 | } |
| 6046 | void AccessorInfoPrint(FILE* out); |
| 6047 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6048 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6049 | void AccessorInfoVerify(); |
| 6050 | #endif |
| 6051 | |
| 6052 | static const int kGetterOffset = HeapObject::kHeaderSize; |
| 6053 | static const int kSetterOffset = kGetterOffset + kPointerSize; |
| 6054 | static const int kDataOffset = kSetterOffset + kPointerSize; |
| 6055 | static const int kNameOffset = kDataOffset + kPointerSize; |
| 6056 | static const int kFlagOffset = kNameOffset + kPointerSize; |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 6057 | static const int kSize = kFlagOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6058 | |
| 6059 | private: |
| 6060 | // Bit positions in flag. |
| 6061 | static const int kAllCanReadBit = 0; |
| 6062 | static const int kAllCanWriteBit = 1; |
| 6063 | static const int kProhibitsOverwritingBit = 2; |
| 6064 | class AttributesField: public BitField<PropertyAttributes, 3, 3> {}; |
| 6065 | |
| 6066 | DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorInfo); |
| 6067 | }; |
| 6068 | |
| 6069 | |
| 6070 | class AccessCheckInfo: public Struct { |
| 6071 | public: |
| 6072 | DECL_ACCESSORS(named_callback, Object) |
| 6073 | DECL_ACCESSORS(indexed_callback, Object) |
| 6074 | DECL_ACCESSORS(data, Object) |
| 6075 | |
| 6076 | static inline AccessCheckInfo* cast(Object* obj); |
| 6077 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6078 | #ifdef OBJECT_PRINT |
| 6079 | inline void AccessCheckInfoPrint() { |
| 6080 | AccessCheckInfoPrint(stdout); |
| 6081 | } |
| 6082 | void AccessCheckInfoPrint(FILE* out); |
| 6083 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6084 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6085 | void AccessCheckInfoVerify(); |
| 6086 | #endif |
| 6087 | |
| 6088 | static const int kNamedCallbackOffset = HeapObject::kHeaderSize; |
| 6089 | static const int kIndexedCallbackOffset = kNamedCallbackOffset + kPointerSize; |
| 6090 | static const int kDataOffset = kIndexedCallbackOffset + kPointerSize; |
| 6091 | static const int kSize = kDataOffset + kPointerSize; |
| 6092 | |
| 6093 | private: |
| 6094 | DISALLOW_IMPLICIT_CONSTRUCTORS(AccessCheckInfo); |
| 6095 | }; |
| 6096 | |
| 6097 | |
| 6098 | class InterceptorInfo: public Struct { |
| 6099 | public: |
| 6100 | DECL_ACCESSORS(getter, Object) |
| 6101 | DECL_ACCESSORS(setter, Object) |
| 6102 | DECL_ACCESSORS(query, Object) |
| 6103 | DECL_ACCESSORS(deleter, Object) |
| 6104 | DECL_ACCESSORS(enumerator, Object) |
| 6105 | DECL_ACCESSORS(data, Object) |
| 6106 | |
| 6107 | static inline InterceptorInfo* cast(Object* obj); |
| 6108 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6109 | #ifdef OBJECT_PRINT |
| 6110 | inline void InterceptorInfoPrint() { |
| 6111 | InterceptorInfoPrint(stdout); |
| 6112 | } |
| 6113 | void InterceptorInfoPrint(FILE* out); |
| 6114 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6115 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6116 | void InterceptorInfoVerify(); |
| 6117 | #endif |
| 6118 | |
| 6119 | static const int kGetterOffset = HeapObject::kHeaderSize; |
| 6120 | static const int kSetterOffset = kGetterOffset + kPointerSize; |
| 6121 | static const int kQueryOffset = kSetterOffset + kPointerSize; |
| 6122 | static const int kDeleterOffset = kQueryOffset + kPointerSize; |
| 6123 | static const int kEnumeratorOffset = kDeleterOffset + kPointerSize; |
| 6124 | static const int kDataOffset = kEnumeratorOffset + kPointerSize; |
| 6125 | static const int kSize = kDataOffset + kPointerSize; |
| 6126 | |
| 6127 | private: |
| 6128 | DISALLOW_IMPLICIT_CONSTRUCTORS(InterceptorInfo); |
| 6129 | }; |
| 6130 | |
| 6131 | |
| 6132 | class CallHandlerInfo: public Struct { |
| 6133 | public: |
| 6134 | DECL_ACCESSORS(callback, Object) |
| 6135 | DECL_ACCESSORS(data, Object) |
| 6136 | |
| 6137 | static inline CallHandlerInfo* cast(Object* obj); |
| 6138 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6139 | #ifdef OBJECT_PRINT |
| 6140 | inline void CallHandlerInfoPrint() { |
| 6141 | CallHandlerInfoPrint(stdout); |
| 6142 | } |
| 6143 | void CallHandlerInfoPrint(FILE* out); |
| 6144 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6145 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6146 | void CallHandlerInfoVerify(); |
| 6147 | #endif |
| 6148 | |
| 6149 | static const int kCallbackOffset = HeapObject::kHeaderSize; |
| 6150 | static const int kDataOffset = kCallbackOffset + kPointerSize; |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 6151 | static const int kSize = kDataOffset + kPointerSize; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6152 | |
| 6153 | private: |
| 6154 | DISALLOW_IMPLICIT_CONSTRUCTORS(CallHandlerInfo); |
| 6155 | }; |
| 6156 | |
| 6157 | |
| 6158 | class TemplateInfo: public Struct { |
| 6159 | public: |
| 6160 | DECL_ACCESSORS(tag, Object) |
| 6161 | DECL_ACCESSORS(property_list, Object) |
| 6162 | |
| 6163 | #ifdef DEBUG |
| 6164 | void TemplateInfoVerify(); |
| 6165 | #endif |
| 6166 | |
| 6167 | static const int kTagOffset = HeapObject::kHeaderSize; |
| 6168 | static const int kPropertyListOffset = kTagOffset + kPointerSize; |
| 6169 | static const int kHeaderSize = kPropertyListOffset + kPointerSize; |
| 6170 | protected: |
| 6171 | friend class AGCCVersionRequiresThisClassToHaveAFriendSoHereItIs; |
| 6172 | DISALLOW_IMPLICIT_CONSTRUCTORS(TemplateInfo); |
| 6173 | }; |
| 6174 | |
| 6175 | |
| 6176 | class FunctionTemplateInfo: public TemplateInfo { |
| 6177 | public: |
| 6178 | DECL_ACCESSORS(serial_number, Object) |
| 6179 | DECL_ACCESSORS(call_code, Object) |
| 6180 | DECL_ACCESSORS(property_accessors, Object) |
| 6181 | DECL_ACCESSORS(prototype_template, Object) |
| 6182 | DECL_ACCESSORS(parent_template, Object) |
| 6183 | DECL_ACCESSORS(named_property_handler, Object) |
| 6184 | DECL_ACCESSORS(indexed_property_handler, Object) |
| 6185 | DECL_ACCESSORS(instance_template, Object) |
| 6186 | DECL_ACCESSORS(class_name, Object) |
| 6187 | DECL_ACCESSORS(signature, Object) |
| 6188 | DECL_ACCESSORS(instance_call_handler, Object) |
| 6189 | DECL_ACCESSORS(access_check_info, Object) |
| 6190 | DECL_ACCESSORS(flag, Smi) |
| 6191 | |
| 6192 | // Following properties use flag bits. |
| 6193 | DECL_BOOLEAN_ACCESSORS(hidden_prototype) |
| 6194 | DECL_BOOLEAN_ACCESSORS(undetectable) |
| 6195 | // If the bit is set, object instances created by this function |
| 6196 | // requires access check. |
| 6197 | DECL_BOOLEAN_ACCESSORS(needs_access_check) |
| 6198 | |
| 6199 | static inline FunctionTemplateInfo* cast(Object* obj); |
| 6200 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6201 | #ifdef OBJECT_PRINT |
| 6202 | inline void FunctionTemplateInfoPrint() { |
| 6203 | FunctionTemplateInfoPrint(stdout); |
| 6204 | } |
| 6205 | void FunctionTemplateInfoPrint(FILE* out); |
| 6206 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6207 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6208 | void FunctionTemplateInfoVerify(); |
| 6209 | #endif |
| 6210 | |
| 6211 | static const int kSerialNumberOffset = TemplateInfo::kHeaderSize; |
| 6212 | static const int kCallCodeOffset = kSerialNumberOffset + kPointerSize; |
| 6213 | static const int kPropertyAccessorsOffset = kCallCodeOffset + kPointerSize; |
| 6214 | static const int kPrototypeTemplateOffset = |
| 6215 | kPropertyAccessorsOffset + kPointerSize; |
| 6216 | static const int kParentTemplateOffset = |
| 6217 | kPrototypeTemplateOffset + kPointerSize; |
| 6218 | static const int kNamedPropertyHandlerOffset = |
| 6219 | kParentTemplateOffset + kPointerSize; |
| 6220 | static const int kIndexedPropertyHandlerOffset = |
| 6221 | kNamedPropertyHandlerOffset + kPointerSize; |
| 6222 | static const int kInstanceTemplateOffset = |
| 6223 | kIndexedPropertyHandlerOffset + kPointerSize; |
| 6224 | static const int kClassNameOffset = kInstanceTemplateOffset + kPointerSize; |
| 6225 | static const int kSignatureOffset = kClassNameOffset + kPointerSize; |
| 6226 | static const int kInstanceCallHandlerOffset = kSignatureOffset + kPointerSize; |
| 6227 | static const int kAccessCheckInfoOffset = |
| 6228 | kInstanceCallHandlerOffset + kPointerSize; |
| 6229 | static const int kFlagOffset = kAccessCheckInfoOffset + kPointerSize; |
| 6230 | static const int kSize = kFlagOffset + kPointerSize; |
| 6231 | |
| 6232 | private: |
| 6233 | // Bit position in the flag, from least significant bit position. |
| 6234 | static const int kHiddenPrototypeBit = 0; |
| 6235 | static const int kUndetectableBit = 1; |
| 6236 | static const int kNeedsAccessCheckBit = 2; |
| 6237 | |
| 6238 | DISALLOW_IMPLICIT_CONSTRUCTORS(FunctionTemplateInfo); |
| 6239 | }; |
| 6240 | |
| 6241 | |
| 6242 | class ObjectTemplateInfo: public TemplateInfo { |
| 6243 | public: |
| 6244 | DECL_ACCESSORS(constructor, Object) |
| 6245 | DECL_ACCESSORS(internal_field_count, Object) |
| 6246 | |
| 6247 | static inline ObjectTemplateInfo* cast(Object* obj); |
| 6248 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6249 | #ifdef OBJECT_PRINT |
| 6250 | inline void ObjectTemplateInfoPrint() { |
| 6251 | ObjectTemplateInfoPrint(stdout); |
| 6252 | } |
| 6253 | void ObjectTemplateInfoPrint(FILE* out); |
| 6254 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6255 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6256 | void ObjectTemplateInfoVerify(); |
| 6257 | #endif |
| 6258 | |
| 6259 | static const int kConstructorOffset = TemplateInfo::kHeaderSize; |
| 6260 | static const int kInternalFieldCountOffset = |
| 6261 | kConstructorOffset + kPointerSize; |
| 6262 | static const int kSize = kInternalFieldCountOffset + kPointerSize; |
| 6263 | }; |
| 6264 | |
| 6265 | |
| 6266 | class SignatureInfo: public Struct { |
| 6267 | public: |
| 6268 | DECL_ACCESSORS(receiver, Object) |
| 6269 | DECL_ACCESSORS(args, Object) |
| 6270 | |
| 6271 | static inline SignatureInfo* cast(Object* obj); |
| 6272 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6273 | #ifdef OBJECT_PRINT |
| 6274 | inline void SignatureInfoPrint() { |
| 6275 | SignatureInfoPrint(stdout); |
| 6276 | } |
| 6277 | void SignatureInfoPrint(FILE* out); |
| 6278 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6279 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6280 | void SignatureInfoVerify(); |
| 6281 | #endif |
| 6282 | |
| 6283 | static const int kReceiverOffset = Struct::kHeaderSize; |
| 6284 | static const int kArgsOffset = kReceiverOffset + kPointerSize; |
| 6285 | static const int kSize = kArgsOffset + kPointerSize; |
| 6286 | |
| 6287 | private: |
| 6288 | DISALLOW_IMPLICIT_CONSTRUCTORS(SignatureInfo); |
| 6289 | }; |
| 6290 | |
| 6291 | |
| 6292 | class TypeSwitchInfo: public Struct { |
| 6293 | public: |
| 6294 | DECL_ACCESSORS(types, Object) |
| 6295 | |
| 6296 | static inline TypeSwitchInfo* cast(Object* obj); |
| 6297 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6298 | #ifdef OBJECT_PRINT |
| 6299 | inline void TypeSwitchInfoPrint() { |
| 6300 | TypeSwitchInfoPrint(stdout); |
| 6301 | } |
| 6302 | void TypeSwitchInfoPrint(FILE* out); |
| 6303 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6304 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6305 | void TypeSwitchInfoVerify(); |
| 6306 | #endif |
| 6307 | |
| 6308 | static const int kTypesOffset = Struct::kHeaderSize; |
| 6309 | static const int kSize = kTypesOffset + kPointerSize; |
| 6310 | }; |
| 6311 | |
| 6312 | |
| 6313 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 6314 | // The DebugInfo class holds additional information for a function being |
| 6315 | // debugged. |
| 6316 | class DebugInfo: public Struct { |
| 6317 | public: |
| 6318 | // The shared function info for the source being debugged. |
| 6319 | DECL_ACCESSORS(shared, SharedFunctionInfo) |
| 6320 | // Code object for the original code. |
| 6321 | DECL_ACCESSORS(original_code, Code) |
| 6322 | // Code object for the patched code. This code object is the code object |
| 6323 | // currently active for the function. |
| 6324 | DECL_ACCESSORS(code, Code) |
| 6325 | // Fixed array holding status information for each active break point. |
| 6326 | DECL_ACCESSORS(break_points, FixedArray) |
| 6327 | |
| 6328 | // Check if there is a break point at a code position. |
| 6329 | bool HasBreakPoint(int code_position); |
| 6330 | // Get the break point info object for a code position. |
| 6331 | Object* GetBreakPointInfo(int code_position); |
| 6332 | // Clear a break point. |
| 6333 | static void ClearBreakPoint(Handle<DebugInfo> debug_info, |
| 6334 | int code_position, |
| 6335 | Handle<Object> break_point_object); |
| 6336 | // Set a break point. |
| 6337 | static void SetBreakPoint(Handle<DebugInfo> debug_info, int code_position, |
| 6338 | int source_position, int statement_position, |
| 6339 | Handle<Object> break_point_object); |
| 6340 | // Get the break point objects for a code position. |
| 6341 | Object* GetBreakPointObjects(int code_position); |
| 6342 | // Find the break point info holding this break point object. |
| 6343 | static Object* FindBreakPointInfo(Handle<DebugInfo> debug_info, |
| 6344 | Handle<Object> break_point_object); |
| 6345 | // Get the number of break points for this function. |
| 6346 | int GetBreakPointCount(); |
| 6347 | |
| 6348 | static inline DebugInfo* cast(Object* obj); |
| 6349 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6350 | #ifdef OBJECT_PRINT |
| 6351 | inline void DebugInfoPrint() { |
| 6352 | DebugInfoPrint(stdout); |
| 6353 | } |
| 6354 | void DebugInfoPrint(FILE* out); |
| 6355 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6356 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6357 | void DebugInfoVerify(); |
| 6358 | #endif |
| 6359 | |
| 6360 | static const int kSharedFunctionInfoIndex = Struct::kHeaderSize; |
| 6361 | static const int kOriginalCodeIndex = kSharedFunctionInfoIndex + kPointerSize; |
| 6362 | static const int kPatchedCodeIndex = kOriginalCodeIndex + kPointerSize; |
| 6363 | static const int kActiveBreakPointsCountIndex = |
| 6364 | kPatchedCodeIndex + kPointerSize; |
| 6365 | static const int kBreakPointsStateIndex = |
| 6366 | kActiveBreakPointsCountIndex + kPointerSize; |
| 6367 | static const int kSize = kBreakPointsStateIndex + kPointerSize; |
| 6368 | |
| 6369 | private: |
| 6370 | static const int kNoBreakPointInfo = -1; |
| 6371 | |
| 6372 | // Lookup the index in the break_points array for a code position. |
| 6373 | int GetBreakPointInfoIndex(int code_position); |
| 6374 | |
| 6375 | DISALLOW_IMPLICIT_CONSTRUCTORS(DebugInfo); |
| 6376 | }; |
| 6377 | |
| 6378 | |
| 6379 | // The BreakPointInfo class holds information for break points set in a |
| 6380 | // function. The DebugInfo object holds a BreakPointInfo object for each code |
| 6381 | // position with one or more break points. |
| 6382 | class BreakPointInfo: public Struct { |
| 6383 | public: |
| 6384 | // The position in the code for the break point. |
| 6385 | DECL_ACCESSORS(code_position, Smi) |
| 6386 | // The position in the source for the break position. |
| 6387 | DECL_ACCESSORS(source_position, Smi) |
| 6388 | // The position in the source for the last statement before this break |
| 6389 | // position. |
| 6390 | DECL_ACCESSORS(statement_position, Smi) |
| 6391 | // List of related JavaScript break points. |
| 6392 | DECL_ACCESSORS(break_point_objects, Object) |
| 6393 | |
| 6394 | // Removes a break point. |
| 6395 | static void ClearBreakPoint(Handle<BreakPointInfo> info, |
| 6396 | Handle<Object> break_point_object); |
| 6397 | // Set a break point. |
| 6398 | static void SetBreakPoint(Handle<BreakPointInfo> info, |
| 6399 | Handle<Object> break_point_object); |
| 6400 | // Check if break point info has this break point object. |
| 6401 | static bool HasBreakPointObject(Handle<BreakPointInfo> info, |
| 6402 | Handle<Object> break_point_object); |
| 6403 | // Get the number of break points for this code position. |
| 6404 | int GetBreakPointCount(); |
| 6405 | |
| 6406 | static inline BreakPointInfo* cast(Object* obj); |
| 6407 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6408 | #ifdef OBJECT_PRINT |
| 6409 | inline void BreakPointInfoPrint() { |
| 6410 | BreakPointInfoPrint(stdout); |
| 6411 | } |
| 6412 | void BreakPointInfoPrint(FILE* out); |
| 6413 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6414 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6415 | void BreakPointInfoVerify(); |
| 6416 | #endif |
| 6417 | |
| 6418 | static const int kCodePositionIndex = Struct::kHeaderSize; |
| 6419 | static const int kSourcePositionIndex = kCodePositionIndex + kPointerSize; |
| 6420 | static const int kStatementPositionIndex = |
| 6421 | kSourcePositionIndex + kPointerSize; |
| 6422 | static const int kBreakPointObjectsIndex = |
| 6423 | kStatementPositionIndex + kPointerSize; |
| 6424 | static const int kSize = kBreakPointObjectsIndex + kPointerSize; |
| 6425 | |
| 6426 | private: |
| 6427 | DISALLOW_IMPLICIT_CONSTRUCTORS(BreakPointInfo); |
| 6428 | }; |
| 6429 | #endif // ENABLE_DEBUGGER_SUPPORT |
| 6430 | |
| 6431 | |
| 6432 | #undef DECL_BOOLEAN_ACCESSORS |
| 6433 | #undef DECL_ACCESSORS |
| 6434 | |
| 6435 | |
| 6436 | // Abstract base class for visiting, and optionally modifying, the |
| 6437 | // pointers contained in Objects. Used in GC and serialization/deserialization. |
| 6438 | class ObjectVisitor BASE_EMBEDDED { |
| 6439 | public: |
| 6440 | virtual ~ObjectVisitor() {} |
| 6441 | |
| 6442 | // Visits a contiguous arrays of pointers in the half-open range |
| 6443 | // [start, end). Any or all of the values may be modified on return. |
| 6444 | virtual void VisitPointers(Object** start, Object** end) = 0; |
| 6445 | |
| 6446 | // To allow lazy clearing of inline caches the visitor has |
| 6447 | // a rich interface for iterating over Code objects.. |
| 6448 | |
| 6449 | // Visits a code target in the instruction stream. |
| 6450 | virtual void VisitCodeTarget(RelocInfo* rinfo); |
| 6451 | |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 6452 | // Visits a code entry in a JS function. |
| 6453 | virtual void VisitCodeEntry(Address entry_address); |
| 6454 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6455 | // Visits a global property cell reference in the instruction stream. |
| 6456 | virtual void VisitGlobalPropertyCell(RelocInfo* rinfo); |
| 6457 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6458 | // Visits a runtime entry in the instruction stream. |
| 6459 | virtual void VisitRuntimeEntry(RelocInfo* rinfo) {} |
| 6460 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 6461 | // Visits the resource of an ASCII or two-byte string. |
| 6462 | virtual void VisitExternalAsciiString( |
| 6463 | v8::String::ExternalAsciiStringResource** resource) {} |
| 6464 | virtual void VisitExternalTwoByteString( |
| 6465 | v8::String::ExternalStringResource** resource) {} |
| 6466 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6467 | // Visits a debug call target in the instruction stream. |
| 6468 | virtual void VisitDebugTarget(RelocInfo* rinfo); |
| 6469 | |
| 6470 | // Handy shorthand for visiting a single pointer. |
| 6471 | virtual void VisitPointer(Object** p) { VisitPointers(p, p + 1); } |
| 6472 | |
| 6473 | // Visits a contiguous arrays of external references (references to the C++ |
| 6474 | // heap) in the half-open range [start, end). Any or all of the values |
| 6475 | // may be modified on return. |
| 6476 | virtual void VisitExternalReferences(Address* start, Address* end) {} |
| 6477 | |
| 6478 | inline void VisitExternalReference(Address* p) { |
| 6479 | VisitExternalReferences(p, p + 1); |
| 6480 | } |
| 6481 | |
| 6482 | #ifdef DEBUG |
| 6483 | // Intended for serialization/deserialization checking: insert, or |
| 6484 | // check for the presence of, a tag at this position in the stream. |
| 6485 | virtual void Synchronize(const char* tag) {} |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 6486 | #else |
| 6487 | inline void Synchronize(const char* tag) {} |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6488 | #endif |
| 6489 | }; |
| 6490 | |
| 6491 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 6492 | class StructBodyDescriptor : public |
| 6493 | FlexibleBodyDescriptor<HeapObject::kHeaderSize> { |
| 6494 | public: |
| 6495 | static inline int SizeOf(Map* map, HeapObject* object) { |
| 6496 | return map->instance_size(); |
| 6497 | } |
| 6498 | }; |
| 6499 | |
| 6500 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6501 | // BooleanBit is a helper class for setting and getting a bit in an |
| 6502 | // integer or Smi. |
| 6503 | class BooleanBit : public AllStatic { |
| 6504 | public: |
| 6505 | static inline bool get(Smi* smi, int bit_position) { |
| 6506 | return get(smi->value(), bit_position); |
| 6507 | } |
| 6508 | |
| 6509 | static inline bool get(int value, int bit_position) { |
| 6510 | return (value & (1 << bit_position)) != 0; |
| 6511 | } |
| 6512 | |
| 6513 | static inline Smi* set(Smi* smi, int bit_position, bool v) { |
| 6514 | return Smi::FromInt(set(smi->value(), bit_position, v)); |
| 6515 | } |
| 6516 | |
| 6517 | static inline int set(int value, int bit_position, bool v) { |
| 6518 | if (v) { |
| 6519 | value |= (1 << bit_position); |
| 6520 | } else { |
| 6521 | value &= ~(1 << bit_position); |
| 6522 | } |
| 6523 | return value; |
| 6524 | } |
| 6525 | }; |
| 6526 | |
| 6527 | } } // namespace v8::internal |
| 6528 | |
| 6529 | #endif // V8_OBJECTS_H_ |