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