Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: src/objects.h

Issue 3197010: Version 2.3.10... (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
Patch Set: Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/mark-compact.cc ('k') | src/objects.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 639 matching lines...) Expand 10 before | Expand all | Expand 10 after
1011 1015
1012 // Iterates over pointers contained in the object (including the Map) 1016 // Iterates over pointers contained in the object (including the Map)
1013 void Iterate(ObjectVisitor* v); 1017 void Iterate(ObjectVisitor* v);
1014 1018
1015 // Iterates over all pointers contained in the object except the 1019 // Iterates over all pointers contained in the object except the
1016 // first map pointer. The object type is given in the first 1020 // first map pointer. The object type is given in the first
1017 // parameter. This function does not access the map pointer in the 1021 // parameter. This function does not access the map pointer in the
1018 // object, and so is safe to call while the map pointer is modified. 1022 // object, and so is safe to call while the map pointer is modified.
1019 void IterateBody(InstanceType type, int object_size, ObjectVisitor* v); 1023 void IterateBody(InstanceType type, int object_size, ObjectVisitor* v);
1020 1024
1021 // This method only applies to struct objects. Iterates over all the fields
1022 // of this struct.
1023 void IterateStructBody(int object_size, ObjectVisitor* v);
1024
1025 // Returns the heap object's size in bytes 1025 // Returns the heap object's size in bytes
1026 inline int Size(); 1026 inline int Size();
1027 1027
1028 // Given a heap object's map pointer, returns the heap size in bytes 1028 // Given a heap object's map pointer, returns the heap size in bytes
1029 // Useful when the map pointer field is used for other purposes. 1029 // Useful when the map pointer field is used for other purposes.
1030 // GC internal. 1030 // GC internal.
1031 inline int SizeFromMap(Map* map); 1031 inline int SizeFromMap(Map* map);
1032 1032
1033 // Support for the marking heap objects during the marking phase of GC. 1033 // Support for the marking heap objects during the marking phase of GC.
1034 // True if the object is marked live. 1034 // True if the object is marked live.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 1093
1094 STATIC_CHECK(kMapOffset == Internals::kHeapObjectMapOffset); 1094 STATIC_CHECK(kMapOffset == Internals::kHeapObjectMapOffset);
1095 1095
1096 protected: 1096 protected:
1097 // helpers for calling an ObjectVisitor to iterate over pointers in the 1097 // helpers for calling an ObjectVisitor to iterate over pointers in the
1098 // half-open range [start, end) specified as integer offsets 1098 // half-open range [start, end) specified as integer offsets
1099 inline void IteratePointers(ObjectVisitor* v, int start, int end); 1099 inline void IteratePointers(ObjectVisitor* v, int start, int end);
1100 // as above, for the single element at "offset" 1100 // as above, for the single element at "offset"
1101 inline void IteratePointer(ObjectVisitor* v, int offset); 1101 inline void IteratePointer(ObjectVisitor* v, int offset);
1102 1102
1103 // Computes the object size from the map.
1104 // Should only be used from SizeFromMap.
1105 int SlowSizeFromMap(Map* map);
1106
1107 private: 1103 private:
1108 DISALLOW_IMPLICIT_CONSTRUCTORS(HeapObject); 1104 DISALLOW_IMPLICIT_CONSTRUCTORS(HeapObject);
1109 }; 1105 };
1110 1106
1111 1107
1112 #define SLOT_ADDR(obj, offset) \ 1108 #define SLOT_ADDR(obj, offset) \
1113 reinterpret_cast<Object**>((obj)->address() + offset) 1109 reinterpret_cast<Object**>((obj)->address() + offset)
1114 1110
1115 // This class describes a body of an object of a fixed size 1111 // 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) 1112 // in which all pointer fields are located in the [start_offset, end_offset)
(...skipping 1763 matching lines...) Expand 10 before | Expand all | Expand 10 after
2880 static inline InlineCacheState ExtractICStateFromFlags(Flags flags); 2876 static inline InlineCacheState ExtractICStateFromFlags(Flags flags);
2881 static inline InLoopFlag ExtractICInLoopFromFlags(Flags flags); 2877 static inline InLoopFlag ExtractICInLoopFromFlags(Flags flags);
2882 static inline PropertyType ExtractTypeFromFlags(Flags flags); 2878 static inline PropertyType ExtractTypeFromFlags(Flags flags);
2883 static inline int ExtractArgumentsCountFromFlags(Flags flags); 2879 static inline int ExtractArgumentsCountFromFlags(Flags flags);
2884 static inline InlineCacheHolderFlag ExtractCacheHolderFromFlags(Flags flags); 2880 static inline InlineCacheHolderFlag ExtractCacheHolderFromFlags(Flags flags);
2885 static inline Flags RemoveTypeFromFlags(Flags flags); 2881 static inline Flags RemoveTypeFromFlags(Flags flags);
2886 2882
2887 // Convert a target address into a code object. 2883 // Convert a target address into a code object.
2888 static inline Code* GetCodeFromTargetAddress(Address address); 2884 static inline Code* GetCodeFromTargetAddress(Address address);
2889 2885
2886 // Convert an entry address into an object.
2887 static inline Object* GetObjectFromEntryAddress(Address location_of_address);
2888
2890 // Returns the address of the first instruction. 2889 // Returns the address of the first instruction.
2891 inline byte* instruction_start(); 2890 inline byte* instruction_start();
2892 2891
2893 // Returns the address right after the last instruction. 2892 // Returns the address right after the last instruction.
2894 inline byte* instruction_end(); 2893 inline byte* instruction_end();
2895 2894
2896 // Returns the size of the instructions, padding, and relocation information. 2895 // Returns the size of the instructions, padding, and relocation information.
2897 inline int body_size(); 2896 inline int body_size();
2898 2897
2899 // Returns the address of the first relocation info (read backwards!). 2898 // Returns the address of the first relocation info (read backwards!).
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
2986 }; 2985 };
2987 2986
2988 2987
2989 // All heap objects have a Map that describes their structure. 2988 // All heap objects have a Map that describes their structure.
2990 // A Map contains information about: 2989 // A Map contains information about:
2991 // - Size information about the object 2990 // - Size information about the object
2992 // - How to iterate over an object (for garbage collection) 2991 // - How to iterate over an object (for garbage collection)
2993 class Map: public HeapObject { 2992 class Map: public HeapObject {
2994 public: 2993 public:
2995 // Instance size. 2994 // Instance size.
2995 // Size in bytes or kVariableSizeSentinel if instances do not have
2996 // a fixed size.
2996 inline int instance_size(); 2997 inline int instance_size();
2997 inline void set_instance_size(int value); 2998 inline void set_instance_size(int value);
2998 2999
2999 // Count of properties allocated in the object. 3000 // Count of properties allocated in the object.
3000 inline int inobject_properties(); 3001 inline int inobject_properties();
3001 inline void set_inobject_properties(int value); 3002 inline void set_inobject_properties(int value);
3002 3003
3003 // Count of property fields pre-allocated in the object when first allocated. 3004 // Count of property fields pre-allocated in the object when first allocated.
3004 inline int pre_allocated_property_fields(); 3005 inline int pre_allocated_property_fields();
3005 inline void set_pre_allocated_property_fields(int value); 3006 inline void set_pre_allocated_property_fields(int value);
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after
3700 // set to 'value', but there is no guarantees on instances created 3701 // set to 'value', but there is no guarantees on instances created
3701 // before. 3702 // before.
3702 Object* SetInstanceClassName(String* name); 3703 Object* SetInstanceClassName(String* name);
3703 3704
3704 // Returns if this function has been compiled to native code yet. 3705 // Returns if this function has been compiled to native code yet.
3705 inline bool is_compiled(); 3706 inline bool is_compiled();
3706 3707
3707 // Casting. 3708 // Casting.
3708 static inline JSFunction* cast(Object* obj); 3709 static inline JSFunction* cast(Object* obj);
3709 3710
3711 // Iterates the objects, including code objects indirectly referenced
3712 // through pointers to the first instruction in the code object.
3713 void JSFunctionIterateBody(int object_size, ObjectVisitor* v);
3714
3710 // Dispatched behavior. 3715 // Dispatched behavior.
3711 #ifdef DEBUG 3716 #ifdef DEBUG
3712 void JSFunctionPrint(); 3717 void JSFunctionPrint();
3713 void JSFunctionVerify(); 3718 void JSFunctionVerify();
3714 #endif 3719 #endif
3715 3720
3716 // Returns the number of allocated literals. 3721 // Returns the number of allocated literals.
3717 inline int NumberOfLiterals(); 3722 inline int NumberOfLiterals();
3718 3723
3719 // Retrieve the global context from a function's literal array. 3724 // Retrieve the global context from a function's literal array.
3720 static Context* GlobalContextFromLiterals(FixedArray* literals); 3725 static Context* GlobalContextFromLiterals(FixedArray* literals);
3721 3726
3722 // Layout descriptors. 3727 // Layout descriptors.
3723 static const int kCodeOffset = JSObject::kHeaderSize; 3728 static const int kCodeEntryOffset = JSObject::kHeaderSize;
3724 static const int kPrototypeOrInitialMapOffset = 3729 static const int kPrototypeOrInitialMapOffset =
3725 kCodeOffset + kPointerSize; 3730 kCodeEntryOffset + kPointerSize;
3726 static const int kSharedFunctionInfoOffset = 3731 static const int kSharedFunctionInfoOffset =
3727 kPrototypeOrInitialMapOffset + kPointerSize; 3732 kPrototypeOrInitialMapOffset + kPointerSize;
3728 static const int kContextOffset = kSharedFunctionInfoOffset + kPointerSize; 3733 static const int kContextOffset = kSharedFunctionInfoOffset + kPointerSize;
3729 static const int kLiteralsOffset = kContextOffset + kPointerSize; 3734 static const int kLiteralsOffset = kContextOffset + kPointerSize;
3730 static const int kSize = kLiteralsOffset + kPointerSize; 3735 static const int kSize = kLiteralsOffset + kPointerSize;
3731 3736
3732 // Layout of the literals array. 3737 // Layout of the literals array.
3733 static const int kLiteralsPrefixSize = 1; 3738 static const int kLiteralsPrefixSize = 1;
3734 static const int kLiteralGlobalContextIndex = 0; 3739 static const int kLiteralGlobalContextIndex = 0;
3735 private: 3740 private:
(...skipping 1694 matching lines...) Expand 10 before | Expand all | Expand 10 after
5430 // Visits a contiguous arrays of pointers in the half-open range 5435 // Visits a contiguous arrays of pointers in the half-open range
5431 // [start, end). Any or all of the values may be modified on return. 5436 // [start, end). Any or all of the values may be modified on return.
5432 virtual void VisitPointers(Object** start, Object** end) = 0; 5437 virtual void VisitPointers(Object** start, Object** end) = 0;
5433 5438
5434 // To allow lazy clearing of inline caches the visitor has 5439 // To allow lazy clearing of inline caches the visitor has
5435 // a rich interface for iterating over Code objects.. 5440 // a rich interface for iterating over Code objects..
5436 5441
5437 // Visits a code target in the instruction stream. 5442 // Visits a code target in the instruction stream.
5438 virtual void VisitCodeTarget(RelocInfo* rinfo); 5443 virtual void VisitCodeTarget(RelocInfo* rinfo);
5439 5444
5445 // Visits a code entry in a JS function.
5446 virtual void VisitCodeEntry(Address entry_address);
5447
5440 // Visits a runtime entry in the instruction stream. 5448 // Visits a runtime entry in the instruction stream.
5441 virtual void VisitRuntimeEntry(RelocInfo* rinfo) {} 5449 virtual void VisitRuntimeEntry(RelocInfo* rinfo) {}
5442 5450
5443 // Visits the resource of an ASCII or two-byte string. 5451 // Visits the resource of an ASCII or two-byte string.
5444 virtual void VisitExternalAsciiString( 5452 virtual void VisitExternalAsciiString(
5445 v8::String::ExternalAsciiStringResource** resource) {} 5453 v8::String::ExternalAsciiStringResource** resource) {}
5446 virtual void VisitExternalTwoByteString( 5454 virtual void VisitExternalTwoByteString(
5447 v8::String::ExternalStringResource** resource) {} 5455 v8::String::ExternalStringResource** resource) {}
5448 5456
5449 // Visits a debug call target in the instruction stream. 5457 // Visits a debug call target in the instruction stream.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
5502 } else { 5510 } else {
5503 value &= ~(1 << bit_position); 5511 value &= ~(1 << bit_position);
5504 } 5512 }
5505 return value; 5513 return value;
5506 } 5514 }
5507 }; 5515 };
5508 5516
5509 } } // namespace v8::internal 5517 } } // namespace v8::internal
5510 5518
5511 #endif // V8_OBJECTS_H_ 5519 #endif // V8_OBJECTS_H_
OLDNEW
« no previous file with comments | « src/mark-compact.cc ('k') | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698