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