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

Side by Side Diff: src/objects.h

Issue 234573005: Clean up the public interface of Map. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 8 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 | « no previous file | 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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 6187 matching lines...) Expand 10 before | Expand all | Expand 10 after
6198 6198
6199 // Returns true if the current map doesn't have DICTIONARY_ELEMENTS but if a 6199 // Returns true if the current map doesn't have DICTIONARY_ELEMENTS but if a
6200 // map with DICTIONARY_ELEMENTS was found in the prototype chain. 6200 // map with DICTIONARY_ELEMENTS was found in the prototype chain.
6201 bool DictionaryElementsInPrototypeChainOnly(); 6201 bool DictionaryElementsInPrototypeChainOnly();
6202 6202
6203 inline bool HasTransitionArray(); 6203 inline bool HasTransitionArray();
6204 inline bool HasElementsTransition(); 6204 inline bool HasElementsTransition();
6205 inline Map* elements_transition_map(); 6205 inline Map* elements_transition_map();
6206 static Handle<TransitionArray> SetElementsTransitionMap( 6206 static Handle<TransitionArray> SetElementsTransitionMap(
6207 Handle<Map> map, Handle<Map> transitioned_map); 6207 Handle<Map> map, Handle<Map> transitioned_map);
6208 inline void SetTransition(int transition_index, Map* target);
6209 inline Map* GetTransition(int transition_index); 6208 inline Map* GetTransition(int transition_index);
6210 inline int SearchTransition(Name* name); 6209 inline int SearchTransition(Name* name);
6211 inline FixedArrayBase* GetInitialElements(); 6210 inline FixedArrayBase* GetInitialElements();
6212 6211
6213 DECL_ACCESSORS(transitions, TransitionArray) 6212 DECL_ACCESSORS(transitions, TransitionArray)
6214 inline void ClearTransitions(Heap* heap,
6215 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
6216
6217 void DeprecateTransitionTree();
6218 void DeprecateTarget(Name* key, DescriptorArray* new_descriptors);
6219 6213
6220 Map* FindRootMap(); 6214 Map* FindRootMap();
6221 Map* FindUpdatedMap(int verbatim, int length, DescriptorArray* descriptors);
6222 Map* FindLastMatchMap(int verbatim, int length, DescriptorArray* descriptors);
6223 6215
6224 inline int GetInObjectPropertyOffset(int index); 6216 inline int GetInObjectPropertyOffset(int index);
6225 6217
6226 int NumberOfFields(); 6218 int NumberOfFields();
6227 6219
6228 bool InstancesNeedRewriting(Map* target, 6220 bool InstancesNeedRewriting(Map* target,
6229 int target_number_of_fields, 6221 int target_number_of_fields,
6230 int target_inobject, 6222 int target_inobject,
6231 int target_unused); 6223 int target_unused);
6232 static Handle<Map> GeneralizeAllFieldRepresentations( 6224 static Handle<Map> GeneralizeAllFieldRepresentations(
6233 Handle<Map> map, 6225 Handle<Map> map,
6234 Representation new_representation); 6226 Representation new_representation);
6235 static Handle<Map> GeneralizeRepresentation( 6227 static Handle<Map> GeneralizeRepresentation(
6236 Handle<Map> map, 6228 Handle<Map> map,
6237 int modify_index, 6229 int modify_index,
6238 Representation new_representation, 6230 Representation new_representation,
6239 StoreMode store_mode); 6231 StoreMode store_mode);
6240 static Handle<Map> CopyGeneralizeAllRepresentations( 6232 static Handle<Map> CopyGeneralizeAllRepresentations(
6241 Handle<Map> map, 6233 Handle<Map> map,
6242 int modify_index, 6234 int modify_index,
6243 StoreMode store_mode, 6235 StoreMode store_mode,
6244 PropertyAttributes attributes, 6236 PropertyAttributes attributes,
6245 const char* reason); 6237 const char* reason);
6246 6238
6247 void PrintGeneralization(FILE* file,
6248 const char* reason,
6249 int modify_index,
6250 int split,
6251 int descriptors,
6252 bool constant_to_field,
6253 Representation old_representation,
6254 Representation new_representation);
6255
6256 // Returns the constructor name (the name (possibly, inferred name) of the 6239 // Returns the constructor name (the name (possibly, inferred name) of the
6257 // function that was used to instantiate the object). 6240 // function that was used to instantiate the object).
6258 String* constructor_name(); 6241 String* constructor_name();
6259 6242
6260 // Tells whether the map is attached to SharedFunctionInfo 6243 // Tells whether the map is attached to SharedFunctionInfo
6261 // (for inobject slack tracking). 6244 // (for inobject slack tracking).
6262 inline void set_attached_to_shared_function_info(bool value); 6245 inline void set_attached_to_shared_function_info(bool value);
6263 6246
6264 inline bool attached_to_shared_function_info(); 6247 inline bool attached_to_shared_function_info();
6265 6248
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
6311 6294
6312 // [prototype transitions]: cache of prototype transitions. 6295 // [prototype transitions]: cache of prototype transitions.
6313 // Prototype transition is a transition that happens 6296 // Prototype transition is a transition that happens
6314 // when we change object's prototype to a new one. 6297 // when we change object's prototype to a new one.
6315 // Cache format: 6298 // Cache format:
6316 // 0: finger - index of the first free cell in the cache 6299 // 0: finger - index of the first free cell in the cache
6317 // 1: back pointer that overlaps with prototype transitions field. 6300 // 1: back pointer that overlaps with prototype transitions field.
6318 // 2 + 2 * i: prototype 6301 // 2 + 2 * i: prototype
6319 // 3 + 2 * i: target map 6302 // 3 + 2 * i: target map
6320 inline FixedArray* GetPrototypeTransitions(); 6303 inline FixedArray* GetPrototypeTransitions();
6321 static inline void SetPrototypeTransitions(
6322 Handle<Map> map, Handle<FixedArray> prototype_transitions);
6323 inline bool HasPrototypeTransitions(); 6304 inline bool HasPrototypeTransitions();
6324 6305
6325 static const int kProtoTransitionHeaderSize = 1; 6306 static const int kProtoTransitionHeaderSize = 1;
6326 static const int kProtoTransitionNumberOfEntriesOffset = 0; 6307 static const int kProtoTransitionNumberOfEntriesOffset = 0;
6327 static const int kProtoTransitionElementsPerEntry = 2; 6308 static const int kProtoTransitionElementsPerEntry = 2;
6328 static const int kProtoTransitionPrototypeOffset = 0; 6309 static const int kProtoTransitionPrototypeOffset = 0;
6329 static const int kProtoTransitionMapOffset = 1; 6310 static const int kProtoTransitionMapOffset = 1;
6330 6311
6331 inline int NumberOfProtoTransitions() { 6312 inline int NumberOfProtoTransitions() {
6332 FixedArray* cache = GetPrototypeTransitions(); 6313 FixedArray* cache = GetPrototypeTransitions();
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
6404 inline bool CanBeDeprecated(); 6385 inline bool CanBeDeprecated();
6405 // Returns a non-deprecated version of the input. If the input was not 6386 // Returns a non-deprecated version of the input. If the input was not
6406 // deprecated, it is directly returned. Otherwise, the non-deprecated version 6387 // deprecated, it is directly returned. Otherwise, the non-deprecated version
6407 // is found by re-transitioning from the root of the transition tree using the 6388 // is found by re-transitioning from the root of the transition tree using the
6408 // descriptor array of the map. Returns NULL if no updated map is found. 6389 // descriptor array of the map. Returns NULL if no updated map is found.
6409 // This method also applies any pending migrations along the prototype chain. 6390 // This method also applies any pending migrations along the prototype chain.
6410 static Handle<Map> CurrentMapForDeprecated(Handle<Map> map); 6391 static Handle<Map> CurrentMapForDeprecated(Handle<Map> map);
6411 // Same as above, but does not touch the prototype chain. 6392 // Same as above, but does not touch the prototype chain.
6412 static Handle<Map> CurrentMapForDeprecatedInternal(Handle<Map> map); 6393 static Handle<Map> CurrentMapForDeprecatedInternal(Handle<Map> map);
6413 6394
6414 static Handle<Map> RawCopy(Handle<Map> map, int instance_size);
6415 static Handle<Map> CopyDropDescriptors(Handle<Map> map); 6395 static Handle<Map> CopyDropDescriptors(Handle<Map> map);
6416 static Handle<Map> CopyReplaceDescriptors( 6396 static Handle<Map> CopyReplaceDescriptors(
6417 Handle<Map> map, 6397 Handle<Map> map,
6418 Handle<DescriptorArray> descriptors, 6398 Handle<DescriptorArray> descriptors,
6419 TransitionFlag flag, 6399 TransitionFlag flag,
6420 Handle<Name> name, 6400 Handle<Name> name,
6421 SimpleTransitionFlag simple_flag = FULL_TRANSITION); 6401 SimpleTransitionFlag simple_flag = FULL_TRANSITION);
6422 static Handle<Map> CopyReplaceDescriptors( 6402 static Handle<Map> CopyReplaceDescriptors(
6423 Handle<Map> map, 6403 Handle<Map> map,
6424 Handle<DescriptorArray> descriptors, 6404 Handle<DescriptorArray> descriptors,
6425 TransitionFlag flag, 6405 TransitionFlag flag,
6426 SimpleTransitionFlag simple_flag = FULL_TRANSITION); 6406 SimpleTransitionFlag simple_flag = FULL_TRANSITION);
6427 static Handle<Map> CopyInstallDescriptors(
6428 Handle<Map> map,
6429 int new_descriptor,
6430 Handle<DescriptorArray> descriptors);
6431 static Handle<Map> ShareDescriptor(Handle<Map> map,
6432 Handle<DescriptorArray> descriptors,
6433 Descriptor* descriptor);
6434 static Handle<Map> CopyAddDescriptor(Handle<Map> map, 6407 static Handle<Map> CopyAddDescriptor(Handle<Map> map,
6435 Descriptor* descriptor, 6408 Descriptor* descriptor,
6436 TransitionFlag flag); 6409 TransitionFlag flag);
6437 static Handle<Map> CopyInsertDescriptor(Handle<Map> map, 6410 static Handle<Map> CopyInsertDescriptor(Handle<Map> map,
6438 Descriptor* descriptor, 6411 Descriptor* descriptor,
6439 TransitionFlag flag); 6412 TransitionFlag flag);
6440 static Handle<Map> CopyReplaceDescriptor( 6413 static Handle<Map> CopyReplaceDescriptor(Handle<Map> map,
6441 Handle<Map> map, 6414 Handle<DescriptorArray> descriptors,
6442 Handle<DescriptorArray> descriptors, 6415 Descriptor* descriptor,
6443 Descriptor* descriptor, 6416 int index,
6444 int index, 6417 TransitionFlag flag);
6445 TransitionFlag flag);
6446 6418
6447 static Handle<Map> AsElementsKind(Handle<Map> map, ElementsKind kind); 6419 static Handle<Map> AsElementsKind(Handle<Map> map, ElementsKind kind);
6448 6420
6449 static Handle<Map> CopyAsElementsKind(Handle<Map> map, 6421 static Handle<Map> CopyAsElementsKind(Handle<Map> map,
6450 ElementsKind kind, 6422 ElementsKind kind,
6451 TransitionFlag flag); 6423 TransitionFlag flag);
6452 6424
6453 static Handle<Map> CopyForObserved(Handle<Map> map); 6425 static Handle<Map> CopyForObserved(Handle<Map> map);
6454 6426
6455 static Handle<Map> CopyNormalized(Handle<Map> map, 6427 static Handle<Map> CopyNormalized(Handle<Map> map,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
6511 void RemoveFromCodeCache(Name* name, Code* code, int index); 6483 void RemoveFromCodeCache(Name* name, Code* code, int index);
6512 6484
6513 // Set all map transitions from this map to dead maps to null. Also clear 6485 // Set all map transitions from this map to dead maps to null. Also clear
6514 // back pointers in transition targets so that we do not process this map 6486 // back pointers in transition targets so that we do not process this map
6515 // again while following back pointers. 6487 // again while following back pointers.
6516 void ClearNonLiveTransitions(Heap* heap); 6488 void ClearNonLiveTransitions(Heap* heap);
6517 6489
6518 // Computes a hash value for this map, to be used in HashTables and such. 6490 // Computes a hash value for this map, to be used in HashTables and such.
6519 int Hash(); 6491 int Hash();
6520 6492
6521 bool EquivalentToForTransition(Map* other);
6522
6523 // Compares this map to another to see if they describe equivalent objects.
6524 // If |mode| is set to CLEAR_INOBJECT_PROPERTIES, |other| is treated as if
6525 // it had exactly zero inobject properties.
6526 // The "shared" flags of both this map and |other| are ignored.
6527 bool EquivalentToForNormalization(Map* other, PropertyNormalizationMode mode);
6528
6529 // Returns the map that this map transitions to if its elements_kind 6493 // Returns the map that this map transitions to if its elements_kind
6530 // is changed to |elements_kind|, or NULL if no such map is cached yet. 6494 // is changed to |elements_kind|, or NULL if no such map is cached yet.
6531 // |safe_to_add_transitions| is set to false if adding transitions is not 6495 // |safe_to_add_transitions| is set to false if adding transitions is not
6532 // allowed. 6496 // allowed.
6533 Map* LookupElementsTransitionMap(ElementsKind elements_kind); 6497 Map* LookupElementsTransitionMap(ElementsKind elements_kind);
6534 6498
6535 // Returns the transitioned map for this map with the most generic 6499 // Returns the transitioned map for this map with the most generic
6536 // elements_kind that's found in |candidates|, or null handle if no match is 6500 // elements_kind that's found in |candidates|, or null handle if no match is
6537 // found at all. 6501 // found at all.
6538 Handle<Map> FindTransitionedMap(MapHandleList* candidates); 6502 Handle<Map> FindTransitionedMap(MapHandleList* candidates);
6539 Map* FindTransitionedMap(MapList* candidates); 6503 Map* FindTransitionedMap(MapList* candidates);
6540 6504
6541 // Zaps the contents of backing data structures. Note that the
6542 // heap verifier (i.e. VerifyMarkingVisitor) relies on zapping of objects
6543 // holding weak references when incremental marking is used, because it also
6544 // iterates over objects that are otherwise unreachable.
6545 // In general we only want to call these functions in release mode when
6546 // heap verification is turned on.
6547 void ZapPrototypeTransitions();
6548 void ZapTransitions();
6549
6550 bool CanTransition() { 6505 bool CanTransition() {
6551 // Only JSObject and subtypes have map transitions and back pointers. 6506 // Only JSObject and subtypes have map transitions and back pointers.
6552 STATIC_ASSERT(LAST_TYPE == LAST_JS_OBJECT_TYPE); 6507 STATIC_ASSERT(LAST_TYPE == LAST_JS_OBJECT_TYPE);
6553 return instance_type() >= FIRST_JS_OBJECT_TYPE; 6508 return instance_type() >= FIRST_JS_OBJECT_TYPE;
6554 } 6509 }
6555 6510
6556 bool IsJSObjectMap() { 6511 bool IsJSObjectMap() {
6557 return instance_type() >= FIRST_JS_OBJECT_TYPE; 6512 return instance_type() >= FIRST_JS_OBJECT_TYPE;
6558 } 6513 }
6559 bool IsJSGlobalProxyMap() { 6514 bool IsJSGlobalProxyMap() {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
6600 void TraverseTransitionTree(TraverseCallback callback, void* data); 6555 void TraverseTransitionTree(TraverseCallback callback, void* data);
6601 6556
6602 // When you set the prototype of an object using the __proto__ accessor you 6557 // When you set the prototype of an object using the __proto__ accessor you
6603 // need a new map for the object (the prototype is stored in the map). In 6558 // need a new map for the object (the prototype is stored in the map). In
6604 // order not to multiply maps unnecessarily we store these as transitions in 6559 // order not to multiply maps unnecessarily we store these as transitions in
6605 // the original map. That way we can transition to the same map if the same 6560 // the original map. That way we can transition to the same map if the same
6606 // prototype is set, rather than creating a new map every time. The 6561 // prototype is set, rather than creating a new map every time. The
6607 // transitions are in the form of a map where the keys are prototype objects 6562 // transitions are in the form of a map where the keys are prototype objects
6608 // and the values are the maps the are transitioned to. 6563 // and the values are the maps the are transitioned to.
6609 static const int kMaxCachedPrototypeTransitions = 256; 6564 static const int kMaxCachedPrototypeTransitions = 256;
6610 static Handle<Map> GetPrototypeTransition(Handle<Map> map, 6565 static Handle<Map> TransitionToPrototype(Handle<Map> map,
6611 Handle<Object> prototype); 6566 Handle<Object> prototype);
6612 static Handle<Map> PutPrototypeTransition(Handle<Map> map,
6613 Handle<Object> prototype,
6614 Handle<Map> target_map);
6615 6567
6616 static const int kMaxPreAllocatedPropertyFields = 255; 6568 static const int kMaxPreAllocatedPropertyFields = 255;
6617 6569
6618 // Layout description. 6570 // Layout description.
6619 static const int kInstanceSizesOffset = HeapObject::kHeaderSize; 6571 static const int kInstanceSizesOffset = HeapObject::kHeaderSize;
6620 static const int kInstanceAttributesOffset = kInstanceSizesOffset + kIntSize; 6572 static const int kInstanceAttributesOffset = kInstanceSizesOffset + kIntSize;
6621 static const int kPrototypeOffset = kInstanceAttributesOffset + kIntSize; 6573 static const int kPrototypeOffset = kInstanceAttributesOffset + kIntSize;
6622 static const int kConstructorOffset = kPrototypeOffset + kPointerSize; 6574 static const int kConstructorOffset = kPrototypeOffset + kPointerSize;
6623 // Storage for the transition array is overloaded to directly contain a back 6575 // Storage for the transition array is overloaded to directly contain a back
6624 // pointer if unused. When the map has transitions, the back pointer is 6576 // pointer if unused. When the map has transitions, the back pointer is
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
6688 static_cast<int8_t>((FAST_HOLEY_ELEMENTS + 1) << 6640 static_cast<int8_t>((FAST_HOLEY_ELEMENTS + 1) <<
6689 Map::kElementsKindShift) - 1; 6641 Map::kElementsKindShift) - 1;
6690 static const int8_t kMaximumBitField2FastHoleySmiElementValue = 6642 static const int8_t kMaximumBitField2FastHoleySmiElementValue =
6691 static_cast<int8_t>((FAST_HOLEY_SMI_ELEMENTS + 1) << 6643 static_cast<int8_t>((FAST_HOLEY_SMI_ELEMENTS + 1) <<
6692 Map::kElementsKindShift) - 1; 6644 Map::kElementsKindShift) - 1;
6693 6645
6694 typedef FixedBodyDescriptor<kPointerFieldsBeginOffset, 6646 typedef FixedBodyDescriptor<kPointerFieldsBeginOffset,
6695 kPointerFieldsEndOffset, 6647 kPointerFieldsEndOffset,
6696 kSize> BodyDescriptor; 6648 kSize> BodyDescriptor;
6697 6649
6650 // Compares this map to another to see if they describe equivalent objects.
6651 // If |mode| is set to CLEAR_INOBJECT_PROPERTIES, |other| is treated as if
6652 // it had exactly zero inobject properties.
6653 // The "shared" flags of both this map and |other| are ignored.
6654 bool EquivalentToForNormalization(Map* other, PropertyNormalizationMode mode);
6655
6698 private: 6656 private:
6657 bool EquivalentToForTransition(Map* other);
6658 static Handle<Map> RawCopy(Handle<Map> map, int instance_size);
6659 static Handle<Map> ShareDescriptor(Handle<Map> map,
6660 Handle<DescriptorArray> descriptors,
6661 Descriptor* descriptor);
6662 static Handle<Map> CopyInstallDescriptors(
6663 Handle<Map> map,
6664 int new_descriptor,
6665 Handle<DescriptorArray> descriptors);
6666
6667 // Zaps the contents of backing data structures. Note that the
6668 // heap verifier (i.e. VerifyMarkingVisitor) relies on zapping of objects
6669 // holding weak references when incremental marking is used, because it also
6670 // iterates over objects that are otherwise unreachable.
6671 // In general we only want to call these functions in release mode when
6672 // heap verification is turned on.
6673 void ZapPrototypeTransitions();
6674 void ZapTransitions();
6675
6676 void DeprecateTransitionTree();
6677 void DeprecateTarget(Name* key, DescriptorArray* new_descriptors);
6678
6679 Map* FindUpdatedMap(int verbatim, int length, DescriptorArray* descriptors);
6680 Map* FindLastMatchMap(int verbatim, int length, DescriptorArray* descriptors);
6681
6682 void PrintGeneralization(FILE* file,
6683 const char* reason,
6684 int modify_index,
6685 int split,
6686 int descriptors,
6687 bool constant_to_field,
6688 Representation old_representation,
6689 Representation new_representation);
6690
6691 static inline void SetPrototypeTransitions(
6692 Handle<Map> map,
6693 Handle<FixedArray> prototype_transitions);
6694
6695 static Handle<Map> GetPrototypeTransition(Handle<Map> map,
6696 Handle<Object> prototype);
6697 static Handle<Map> PutPrototypeTransition(Handle<Map> map,
6698 Handle<Object> prototype,
6699 Handle<Map> target_map);
6700
6699 DISALLOW_IMPLICIT_CONSTRUCTORS(Map); 6701 DISALLOW_IMPLICIT_CONSTRUCTORS(Map);
6700 }; 6702 };
6701 6703
6702 6704
6703 // An abstract superclass, a marker class really, for simple structure classes. 6705 // An abstract superclass, a marker class really, for simple structure classes.
6704 // It doesn't carry much functionality but allows struct classes to be 6706 // It doesn't carry much functionality but allows struct classes to be
6705 // identified in the type system. 6707 // identified in the type system.
6706 class Struct: public HeapObject { 6708 class Struct: public HeapObject {
6707 public: 6709 public:
6708 inline void InitializeBody(int object_size); 6710 inline void InitializeBody(int object_size);
(...skipping 4313 matching lines...) Expand 10 before | Expand all | Expand 10 after
11022 } else { 11024 } else {
11023 value &= ~(1 << bit_position); 11025 value &= ~(1 << bit_position);
11024 } 11026 }
11025 return value; 11027 return value;
11026 } 11028 }
11027 }; 11029 };
11028 11030
11029 } } // namespace v8::internal 11031 } } // namespace v8::internal
11030 11032
11031 #endif // V8_OBJECTS_H_ 11033 #endif // V8_OBJECTS_H_
OLDNEW
« no previous file with comments | « no previous file | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698