OLD | NEW |
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 | 194 |
195 | 195 |
196 // PropertyNormalizationMode is used to specify whether to keep | 196 // PropertyNormalizationMode is used to specify whether to keep |
197 // inobject properties when normalizing properties of a JSObject. | 197 // inobject properties when normalizing properties of a JSObject. |
198 enum PropertyNormalizationMode { | 198 enum PropertyNormalizationMode { |
199 CLEAR_INOBJECT_PROPERTIES, | 199 CLEAR_INOBJECT_PROPERTIES, |
200 KEEP_INOBJECT_PROPERTIES | 200 KEEP_INOBJECT_PROPERTIES |
201 }; | 201 }; |
202 | 202 |
203 | 203 |
| 204 // Instance size sentinel for objects of variable size. |
| 205 static const int kVariableSizeSentinel = 0; |
| 206 |
| 207 |
204 // All Maps have a field instance_type containing a InstanceType. | 208 // All Maps have a field instance_type containing a InstanceType. |
205 // It describes the type of the instances. | 209 // It describes the type of the instances. |
206 // | 210 // |
207 // As an example, a JavaScript object is a heap object and its map | 211 // As an example, a JavaScript object is a heap object and its map |
208 // instance_type is JS_OBJECT_TYPE. | 212 // instance_type is JS_OBJECT_TYPE. |
209 // | 213 // |
210 // The names of the string instance types are intended to systematically | 214 // The names of the string instance types are intended to systematically |
211 // mirror their encoding in the instance_type field of the map. The default | 215 // mirror their encoding in the instance_type field of the map. The default |
212 // encoding is considered TWO_BYTE. It is not mentioned in the name. ASCII | 216 // encoding is considered TWO_BYTE. It is not mentioned in the name. ASCII |
213 // encoding is mentioned explicitly in the name. Likewise, the default | 217 // encoding is mentioned explicitly in the name. Likewise, the default |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 | 301 |
298 #define INSTANCE_TYPE_LIST(V) \ | 302 #define INSTANCE_TYPE_LIST(V) \ |
299 INSTANCE_TYPE_LIST_ALL(V) \ | 303 INSTANCE_TYPE_LIST_ALL(V) \ |
300 INSTANCE_TYPE_LIST_DEBUGGER(V) | 304 INSTANCE_TYPE_LIST_DEBUGGER(V) |
301 | 305 |
302 | 306 |
303 // Since string types are not consecutive, this macro is used to | 307 // Since string types are not consecutive, this macro is used to |
304 // iterate over them. | 308 // iterate over them. |
305 #define STRING_TYPE_LIST(V) \ | 309 #define STRING_TYPE_LIST(V) \ |
306 V(SYMBOL_TYPE, \ | 310 V(SYMBOL_TYPE, \ |
307 SeqTwoByteString::kAlignedSize, \ | 311 kVariableSizeSentinel, \ |
308 symbol, \ | 312 symbol, \ |
309 Symbol) \ | 313 Symbol) \ |
310 V(ASCII_SYMBOL_TYPE, \ | 314 V(ASCII_SYMBOL_TYPE, \ |
311 SeqAsciiString::kAlignedSize, \ | 315 kVariableSizeSentinel, \ |
312 ascii_symbol, \ | 316 ascii_symbol, \ |
313 AsciiSymbol) \ | 317 AsciiSymbol) \ |
314 V(CONS_SYMBOL_TYPE, \ | 318 V(CONS_SYMBOL_TYPE, \ |
315 ConsString::kSize, \ | 319 ConsString::kSize, \ |
316 cons_symbol, \ | 320 cons_symbol, \ |
317 ConsSymbol) \ | 321 ConsSymbol) \ |
318 V(CONS_ASCII_SYMBOL_TYPE, \ | 322 V(CONS_ASCII_SYMBOL_TYPE, \ |
319 ConsString::kSize, \ | 323 ConsString::kSize, \ |
320 cons_ascii_symbol, \ | 324 cons_ascii_symbol, \ |
321 ConsAsciiSymbol) \ | 325 ConsAsciiSymbol) \ |
322 V(EXTERNAL_SYMBOL_TYPE, \ | 326 V(EXTERNAL_SYMBOL_TYPE, \ |
323 ExternalTwoByteString::kSize, \ | 327 ExternalTwoByteString::kSize, \ |
324 external_symbol, \ | 328 external_symbol, \ |
325 ExternalSymbol) \ | 329 ExternalSymbol) \ |
326 V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE, \ | 330 V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE, \ |
327 ExternalTwoByteString::kSize, \ | 331 ExternalTwoByteString::kSize, \ |
328 external_symbol_with_ascii_data, \ | 332 external_symbol_with_ascii_data, \ |
329 ExternalSymbolWithAsciiData) \ | 333 ExternalSymbolWithAsciiData) \ |
330 V(EXTERNAL_ASCII_SYMBOL_TYPE, \ | 334 V(EXTERNAL_ASCII_SYMBOL_TYPE, \ |
331 ExternalAsciiString::kSize, \ | 335 ExternalAsciiString::kSize, \ |
332 external_ascii_symbol, \ | 336 external_ascii_symbol, \ |
333 ExternalAsciiSymbol) \ | 337 ExternalAsciiSymbol) \ |
334 V(STRING_TYPE, \ | 338 V(STRING_TYPE, \ |
335 SeqTwoByteString::kAlignedSize, \ | 339 kVariableSizeSentinel, \ |
336 string, \ | 340 string, \ |
337 String) \ | 341 String) \ |
338 V(ASCII_STRING_TYPE, \ | 342 V(ASCII_STRING_TYPE, \ |
339 SeqAsciiString::kAlignedSize, \ | 343 kVariableSizeSentinel, \ |
340 ascii_string, \ | 344 ascii_string, \ |
341 AsciiString) \ | 345 AsciiString) \ |
342 V(CONS_STRING_TYPE, \ | 346 V(CONS_STRING_TYPE, \ |
343 ConsString::kSize, \ | 347 ConsString::kSize, \ |
344 cons_string, \ | 348 cons_string, \ |
345 ConsString) \ | 349 ConsString) \ |
346 V(CONS_ASCII_STRING_TYPE, \ | 350 V(CONS_ASCII_STRING_TYPE, \ |
347 ConsString::kSize, \ | 351 ConsString::kSize, \ |
348 cons_ascii_string, \ | 352 cons_ascii_string, \ |
349 ConsAsciiString) \ | 353 ConsAsciiString) \ |
350 V(EXTERNAL_STRING_TYPE, \ | 354 V(EXTERNAL_STRING_TYPE, \ |
351 ExternalTwoByteString::kSize, \ | 355 ExternalTwoByteString::kSize, \ |
352 external_string, \ | 356 external_string, \ |
353 ExternalString) \ | 357 ExternalString) \ |
354 V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE, \ | 358 V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE, \ |
355 ExternalTwoByteString::kSize, \ | 359 ExternalTwoByteString::kSize, \ |
356 external_string_with_ascii_data, \ | 360 external_string_with_ascii_data, \ |
357 ExternalStringWithAsciiData) \ | 361 ExternalStringWithAsciiData) \ |
358 V(EXTERNAL_ASCII_STRING_TYPE, \ | 362 V(EXTERNAL_ASCII_STRING_TYPE, \ |
359 ExternalAsciiString::kSize, \ | 363 ExternalAsciiString::kSize, \ |
360 external_ascii_string, \ | 364 external_ascii_string, \ |
361 ExternalAsciiString) \ | 365 ExternalAsciiString) |
362 | 366 |
363 // A struct is a simple object a set of object-valued fields. Including an | 367 // A struct is a simple object a set of object-valued fields. Including an |
364 // object type in this causes the compiler to generate most of the boilerplate | 368 // object type in this causes the compiler to generate most of the boilerplate |
365 // code for the class including allocation and garbage collection routines, | 369 // code for the class including allocation and garbage collection routines, |
366 // casts and predicates. All you need to define is the class, methods and | 370 // casts and predicates. All you need to define is the class, methods and |
367 // object verification routines. Easy, no? | 371 // object verification routines. Easy, no? |
368 // | 372 // |
369 // Note that for subtle reasons related to the ordering or numerical values of | 373 // Note that for subtle reasons related to the ordering or numerical values of |
370 // type tags, elements in this list have to be added to the INSTANCE_TYPE_LIST | 374 // type tags, elements in this list have to be added to the INSTANCE_TYPE_LIST |
371 // manually. | 375 // manually. |
(...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1093 | 1097 |
1094 STATIC_CHECK(kMapOffset == Internals::kHeapObjectMapOffset); | 1098 STATIC_CHECK(kMapOffset == Internals::kHeapObjectMapOffset); |
1095 | 1099 |
1096 protected: | 1100 protected: |
1097 // helpers for calling an ObjectVisitor to iterate over pointers in the | 1101 // helpers for calling an ObjectVisitor to iterate over pointers in the |
1098 // half-open range [start, end) specified as integer offsets | 1102 // half-open range [start, end) specified as integer offsets |
1099 inline void IteratePointers(ObjectVisitor* v, int start, int end); | 1103 inline void IteratePointers(ObjectVisitor* v, int start, int end); |
1100 // as above, for the single element at "offset" | 1104 // as above, for the single element at "offset" |
1101 inline void IteratePointer(ObjectVisitor* v, int offset); | 1105 inline void IteratePointer(ObjectVisitor* v, int offset); |
1102 | 1106 |
1103 // Computes the object size from the map. | |
1104 // Should only be used from SizeFromMap. | |
1105 int SlowSizeFromMap(Map* map); | |
1106 | |
1107 private: | 1107 private: |
1108 DISALLOW_IMPLICIT_CONSTRUCTORS(HeapObject); | 1108 DISALLOW_IMPLICIT_CONSTRUCTORS(HeapObject); |
1109 }; | 1109 }; |
1110 | 1110 |
1111 | 1111 |
1112 #define SLOT_ADDR(obj, offset) \ | 1112 #define SLOT_ADDR(obj, offset) \ |
1113 reinterpret_cast<Object**>((obj)->address() + offset) | 1113 reinterpret_cast<Object**>((obj)->address() + offset) |
1114 | 1114 |
1115 // This class describes a body of an object of a fixed size | 1115 // This class describes a body of an object of a fixed size |
1116 // in which all pointer fields are located in the [start_offset, end_offset) | 1116 // in which all pointer fields are located in the [start_offset, end_offset) |
(...skipping 1869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2986 }; | 2986 }; |
2987 | 2987 |
2988 | 2988 |
2989 // All heap objects have a Map that describes their structure. | 2989 // All heap objects have a Map that describes their structure. |
2990 // A Map contains information about: | 2990 // A Map contains information about: |
2991 // - Size information about the object | 2991 // - Size information about the object |
2992 // - How to iterate over an object (for garbage collection) | 2992 // - How to iterate over an object (for garbage collection) |
2993 class Map: public HeapObject { | 2993 class Map: public HeapObject { |
2994 public: | 2994 public: |
2995 // Instance size. | 2995 // Instance size. |
| 2996 // Size in bytes or kVariableSizeSentinel if instances do not have |
| 2997 // a fixed size. |
2996 inline int instance_size(); | 2998 inline int instance_size(); |
2997 inline void set_instance_size(int value); | 2999 inline void set_instance_size(int value); |
2998 | 3000 |
2999 // Count of properties allocated in the object. | 3001 // Count of properties allocated in the object. |
3000 inline int inobject_properties(); | 3002 inline int inobject_properties(); |
3001 inline void set_inobject_properties(int value); | 3003 inline void set_inobject_properties(int value); |
3002 | 3004 |
3003 // Count of property fields pre-allocated in the object when first allocated. | 3005 // Count of property fields pre-allocated in the object when first allocated. |
3004 inline int pre_allocated_property_fields(); | 3006 inline int pre_allocated_property_fields(); |
3005 inline void set_pre_allocated_property_fields(int value); | 3007 inline void set_pre_allocated_property_fields(int value); |
(...skipping 2496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5502 } else { | 5504 } else { |
5503 value &= ~(1 << bit_position); | 5505 value &= ~(1 << bit_position); |
5504 } | 5506 } |
5505 return value; | 5507 return value; |
5506 } | 5508 } |
5507 }; | 5509 }; |
5508 | 5510 |
5509 } } // namespace v8::internal | 5511 } } // namespace v8::internal |
5510 | 5512 |
5511 #endif // V8_OBJECTS_H_ | 5513 #endif // V8_OBJECTS_H_ |
OLD | NEW |