| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_OBJECTS_H_ | 5 #ifndef V8_OBJECTS_H_ |
| 6 #define V8_OBJECTS_H_ | 6 #define V8_OBJECTS_H_ |
| 7 | 7 |
| 8 #include <iosfwd> | 8 #include <iosfwd> |
| 9 | 9 |
| 10 #include "src/allocation.h" | 10 #include "src/allocation.h" |
| (...skipping 5851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5862 || elements_kind() == SLOPPY_ARGUMENTS_ELEMENTS; | 5862 || elements_kind() == SLOPPY_ARGUMENTS_ELEMENTS; |
| 5863 } | 5863 } |
| 5864 | 5864 |
| 5865 static bool IsValidElementsTransition(ElementsKind from_kind, | 5865 static bool IsValidElementsTransition(ElementsKind from_kind, |
| 5866 ElementsKind to_kind); | 5866 ElementsKind to_kind); |
| 5867 | 5867 |
| 5868 // Returns true if the current map doesn't have DICTIONARY_ELEMENTS but if a | 5868 // Returns true if the current map doesn't have DICTIONARY_ELEMENTS but if a |
| 5869 // map with DICTIONARY_ELEMENTS was found in the prototype chain. | 5869 // map with DICTIONARY_ELEMENTS was found in the prototype chain. |
| 5870 bool DictionaryElementsInPrototypeChainOnly(); | 5870 bool DictionaryElementsInPrototypeChainOnly(); |
| 5871 | 5871 |
| 5872 inline Map* ElementsTransitionMap(); | 5872 inline bool HasTransitionArray() const; |
| 5873 inline bool HasElementsTransition(); |
| 5874 inline Map* elements_transition_map(); |
| 5873 | 5875 |
| 5876 inline Map* GetTransition(int transition_index); |
| 5877 inline int SearchSpecialTransition(Symbol* name); |
| 5878 inline int SearchTransition(PropertyKind kind, Name* name, |
| 5879 PropertyAttributes attributes); |
| 5874 inline FixedArrayBase* GetInitialElements(); | 5880 inline FixedArrayBase* GetInitialElements(); |
| 5875 | 5881 |
| 5876 DECL_ACCESSORS(raw_transitions, Object) | 5882 DECL_ACCESSORS(transitions, TransitionArray) |
| 5883 inline void init_transitions(Object* undefined); |
| 5884 |
| 5885 static inline Handle<String> ExpectedTransitionKey(Handle<Map> map); |
| 5886 static inline Handle<Map> ExpectedTransitionTarget(Handle<Map> map); |
| 5887 |
| 5888 // Try to follow an existing transition to a field with attributes NONE. The |
| 5889 // return value indicates whether the transition was successful. |
| 5890 static inline Handle<Map> FindTransitionToField(Handle<Map> map, |
| 5891 Handle<Name> key); |
| 5877 | 5892 |
| 5878 Map* FindRootMap(); | 5893 Map* FindRootMap(); |
| 5879 Map* FindFieldOwner(int descriptor); | 5894 Map* FindFieldOwner(int descriptor); |
| 5880 | 5895 |
| 5881 inline int GetInObjectPropertyOffset(int index); | 5896 inline int GetInObjectPropertyOffset(int index); |
| 5882 | 5897 |
| 5883 int NumberOfFields(); | 5898 int NumberOfFields(); |
| 5884 | 5899 |
| 5885 // TODO(ishell): candidate with JSObject::MigrateToMap(). | 5900 // TODO(ishell): candidate with JSObject::MigrateToMap(). |
| 5886 bool InstancesNeedRewriting(Map* target, int target_number_of_fields, | 5901 bool InstancesNeedRewriting(Map* target, int target_number_of_fields, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5940 bool CanUseOptimizationsBasedOnPrototypeRegistry(); | 5955 bool CanUseOptimizationsBasedOnPrototypeRegistry(); |
| 5941 | 5956 |
| 5942 // [constructor]: points back to the function responsible for this map. | 5957 // [constructor]: points back to the function responsible for this map. |
| 5943 // The field overlaps with the back pointer. All maps in a transition tree | 5958 // The field overlaps with the back pointer. All maps in a transition tree |
| 5944 // have the same constructor, so maps with back pointers can walk the | 5959 // have the same constructor, so maps with back pointers can walk the |
| 5945 // back pointer chain until they find the map holding their constructor. | 5960 // back pointer chain until they find the map holding their constructor. |
| 5946 DECL_ACCESSORS(constructor_or_backpointer, Object) | 5961 DECL_ACCESSORS(constructor_or_backpointer, Object) |
| 5947 inline Object* GetConstructor() const; | 5962 inline Object* GetConstructor() const; |
| 5948 inline void SetConstructor(Object* constructor, | 5963 inline void SetConstructor(Object* constructor, |
| 5949 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); | 5964 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
| 5950 // [back pointer]: points back to the parent map from which a transition | |
| 5951 // leads to this map. The field overlaps with the constructor (see above). | |
| 5952 inline Object* GetBackPointer(); | 5965 inline Object* GetBackPointer(); |
| 5953 inline void SetBackPointer(Object* value, | 5966 inline void SetBackPointer(Object* value, |
| 5954 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); | 5967 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
| 5955 | 5968 |
| 5956 // [instance descriptors]: describes the object. | 5969 // [instance descriptors]: describes the object. |
| 5957 DECL_ACCESSORS(instance_descriptors, DescriptorArray) | 5970 DECL_ACCESSORS(instance_descriptors, DescriptorArray) |
| 5958 | 5971 |
| 5959 // [layout descriptor]: describes the object layout. | 5972 // [layout descriptor]: describes the object layout. |
| 5960 DECL_ACCESSORS(layout_descriptor, LayoutDescriptor) | 5973 DECL_ACCESSORS(layout_descriptor, LayoutDescriptor) |
| 5961 // |layout descriptor| accessor which can be used from GC. | 5974 // |layout descriptor| accessor which can be used from GC. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 5974 | 5987 |
| 5975 // [stub cache]: contains stubs compiled for this map. | 5988 // [stub cache]: contains stubs compiled for this map. |
| 5976 DECL_ACCESSORS(code_cache, Object) | 5989 DECL_ACCESSORS(code_cache, Object) |
| 5977 | 5990 |
| 5978 // [dependent code]: list of optimized codes that weakly embed this map. | 5991 // [dependent code]: list of optimized codes that weakly embed this map. |
| 5979 DECL_ACCESSORS(dependent_code, DependentCode) | 5992 DECL_ACCESSORS(dependent_code, DependentCode) |
| 5980 | 5993 |
| 5981 // [weak cell cache]: cache that stores a weak cell pointing to this map. | 5994 // [weak cell cache]: cache that stores a weak cell pointing to this map. |
| 5982 DECL_ACCESSORS(weak_cell_cache, Object) | 5995 DECL_ACCESSORS(weak_cell_cache, Object) |
| 5983 | 5996 |
| 5997 // [prototype transitions]: cache of prototype transitions. |
| 5998 // Prototype transition is a transition that happens |
| 5999 // when we change object's prototype to a new one. |
| 6000 // Cache format: |
| 6001 // 0: finger - index of the first free cell in the cache |
| 6002 // 1 + i: target map |
| 6003 inline FixedArray* GetPrototypeTransitions(); |
| 6004 inline bool HasPrototypeTransitions(); |
| 6005 |
| 6006 static const int kProtoTransitionNumberOfEntriesOffset = 0; |
| 6007 static const int kProtoTransitionHeaderSize = 1; |
| 6008 |
| 6009 inline int NumberOfProtoTransitions() { |
| 6010 FixedArray* cache = GetPrototypeTransitions(); |
| 6011 if (cache->length() == 0) return 0; |
| 6012 return |
| 6013 Smi::cast(cache->get(kProtoTransitionNumberOfEntriesOffset))->value(); |
| 6014 } |
| 6015 |
| 6016 inline void SetNumberOfProtoTransitions(int value) { |
| 6017 FixedArray* cache = GetPrototypeTransitions(); |
| 6018 DCHECK(cache->length() != 0); |
| 6019 cache->set(kProtoTransitionNumberOfEntriesOffset, Smi::FromInt(value)); |
| 6020 } |
| 6021 |
| 5984 inline PropertyDetails GetLastDescriptorDetails(); | 6022 inline PropertyDetails GetLastDescriptorDetails(); |
| 5985 | 6023 |
| 6024 // The size of transition arrays are limited so they do not end up in large |
| 6025 // object space. Otherwise ClearNonLiveTransitions would leak memory while |
| 6026 // applying in-place right trimming. |
| 6027 inline bool CanHaveMoreTransitions(); |
| 6028 |
| 5986 int LastAdded() { | 6029 int LastAdded() { |
| 5987 int number_of_own_descriptors = NumberOfOwnDescriptors(); | 6030 int number_of_own_descriptors = NumberOfOwnDescriptors(); |
| 5988 DCHECK(number_of_own_descriptors > 0); | 6031 DCHECK(number_of_own_descriptors > 0); |
| 5989 return number_of_own_descriptors - 1; | 6032 return number_of_own_descriptors - 1; |
| 5990 } | 6033 } |
| 5991 | 6034 |
| 5992 int NumberOfOwnDescriptors() { | 6035 int NumberOfOwnDescriptors() { |
| 5993 return NumberOfOwnDescriptorsBits::decode(bit_field3()); | 6036 return NumberOfOwnDescriptorsBits::decode(bit_field3()); |
| 5994 } | 6037 } |
| 5995 | 6038 |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6143 // Returns the found code or undefined if absent. | 6186 // Returns the found code or undefined if absent. |
| 6144 Object* FindInCodeCache(Name* name, Code::Flags flags); | 6187 Object* FindInCodeCache(Name* name, Code::Flags flags); |
| 6145 | 6188 |
| 6146 // Returns the non-negative index of the code object if it is in the | 6189 // Returns the non-negative index of the code object if it is in the |
| 6147 // cache and -1 otherwise. | 6190 // cache and -1 otherwise. |
| 6148 int IndexInCodeCache(Object* name, Code* code); | 6191 int IndexInCodeCache(Object* name, Code* code); |
| 6149 | 6192 |
| 6150 // Removes a code object from the code cache at the given index. | 6193 // Removes a code object from the code cache at the given index. |
| 6151 void RemoveFromCodeCache(Name* name, Code* code, int index); | 6194 void RemoveFromCodeCache(Name* name, Code* code, int index); |
| 6152 | 6195 |
| 6196 // Set all map transitions from this map to dead maps to null. Also clear |
| 6197 // back pointers in transition targets so that we do not process this map |
| 6198 // again while following back pointers. |
| 6199 void ClearNonLiveTransitions(Heap* heap); |
| 6200 |
| 6153 // Computes a hash value for this map, to be used in HashTables and such. | 6201 // Computes a hash value for this map, to be used in HashTables and such. |
| 6154 int Hash(); | 6202 int Hash(); |
| 6155 | 6203 |
| 6156 // Returns the map that this map transitions to if its elements_kind | 6204 // Returns the map that this map transitions to if its elements_kind |
| 6157 // is changed to |elements_kind|, or NULL if no such map is cached yet. | 6205 // is changed to |elements_kind|, or NULL if no such map is cached yet. |
| 6158 // |safe_to_add_transitions| is set to false if adding transitions is not | 6206 // |safe_to_add_transitions| is set to false if adding transitions is not |
| 6159 // allowed. | 6207 // allowed. |
| 6160 Map* LookupElementsTransitionMap(ElementsKind elements_kind); | 6208 Map* LookupElementsTransitionMap(ElementsKind elements_kind); |
| 6161 | 6209 |
| 6162 // Returns the transitioned map for this map with the most generic | 6210 // Returns the transitioned map for this map with the most generic |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6208 DECLARE_VERIFIER(Map) | 6256 DECLARE_VERIFIER(Map) |
| 6209 | 6257 |
| 6210 #ifdef VERIFY_HEAP | 6258 #ifdef VERIFY_HEAP |
| 6211 void DictionaryMapVerify(); | 6259 void DictionaryMapVerify(); |
| 6212 void VerifyOmittedMapChecks(); | 6260 void VerifyOmittedMapChecks(); |
| 6213 #endif | 6261 #endif |
| 6214 | 6262 |
| 6215 inline int visitor_id(); | 6263 inline int visitor_id(); |
| 6216 inline void set_visitor_id(int visitor_id); | 6264 inline void set_visitor_id(int visitor_id); |
| 6217 | 6265 |
| 6266 typedef void (*TraverseCallback)(Map* map, void* data); |
| 6267 |
| 6268 void TraverseTransitionTree(TraverseCallback callback, void* data); |
| 6269 |
| 6270 // When you set the prototype of an object using the __proto__ accessor you |
| 6271 // need a new map for the object (the prototype is stored in the map). In |
| 6272 // order not to multiply maps unnecessarily we store these as transitions in |
| 6273 // the original map. That way we can transition to the same map if the same |
| 6274 // prototype is set, rather than creating a new map every time. The |
| 6275 // transitions are in the form of a map where the keys are prototype objects |
| 6276 // and the values are the maps they transition to. |
| 6277 static const int kMaxCachedPrototypeTransitions = 256; |
| 6218 static Handle<Map> TransitionToPrototype(Handle<Map> map, | 6278 static Handle<Map> TransitionToPrototype(Handle<Map> map, |
| 6219 Handle<Object> prototype, | 6279 Handle<Object> prototype, |
| 6220 PrototypeOptimizationMode mode); | 6280 PrototypeOptimizationMode mode); |
| 6221 | 6281 |
| 6222 static const int kMaxPreAllocatedPropertyFields = 255; | 6282 static const int kMaxPreAllocatedPropertyFields = 255; |
| 6223 | 6283 |
| 6224 // Layout description. | 6284 // Layout description. |
| 6225 static const int kInstanceSizesOffset = HeapObject::kHeaderSize; | 6285 static const int kInstanceSizesOffset = HeapObject::kHeaderSize; |
| 6226 static const int kInstanceAttributesOffset = kInstanceSizesOffset + kIntSize; | 6286 static const int kInstanceAttributesOffset = kInstanceSizesOffset + kIntSize; |
| 6227 static const int kBitField3Offset = kInstanceAttributesOffset + kIntSize; | 6287 static const int kBitField3Offset = kInstanceAttributesOffset + kIntSize; |
| 6228 static const int kPrototypeOffset = kBitField3Offset + kPointerSize; | 6288 static const int kPrototypeOffset = kBitField3Offset + kPointerSize; |
| 6229 static const int kConstructorOrBackPointerOffset = | 6289 static const int kConstructorOrBackPointerOffset = |
| 6230 kPrototypeOffset + kPointerSize; | 6290 kPrototypeOffset + kPointerSize; |
| 6231 // When there is only one transition, it is stored directly in this field; | |
| 6232 // otherwise a transition array is used. | |
| 6233 // For prototype maps, this slot is used to store a pointer to the prototype | |
| 6234 // object using this map. | |
| 6235 static const int kTransitionsOffset = | 6291 static const int kTransitionsOffset = |
| 6236 kConstructorOrBackPointerOffset + kPointerSize; | 6292 kConstructorOrBackPointerOffset + kPointerSize; |
| 6237 static const int kDescriptorsOffset = kTransitionsOffset + kPointerSize; | 6293 static const int kDescriptorsOffset = kTransitionsOffset + kPointerSize; |
| 6238 #if V8_DOUBLE_FIELDS_UNBOXING | 6294 #if V8_DOUBLE_FIELDS_UNBOXING |
| 6239 static const int kLayoutDecriptorOffset = kDescriptorsOffset + kPointerSize; | 6295 static const int kLayoutDecriptorOffset = kDescriptorsOffset + kPointerSize; |
| 6240 static const int kCodeCacheOffset = kLayoutDecriptorOffset + kPointerSize; | 6296 static const int kCodeCacheOffset = kLayoutDecriptorOffset + kPointerSize; |
| 6241 #else | 6297 #else |
| 6242 static const int kLayoutDecriptorOffset = 1; // Must not be ever accessed. | 6298 static const int kLayoutDecriptorOffset = 1; // Must not be ever accessed. |
| 6243 static const int kCodeCacheOffset = kDescriptorsOffset + kPointerSize; | 6299 static const int kCodeCacheOffset = kDescriptorsOffset + kPointerSize; |
| 6244 #endif | 6300 #endif |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6367 PropertyNormalizationMode mode); | 6423 PropertyNormalizationMode mode); |
| 6368 | 6424 |
| 6369 // Fires when the layout of an object with a leaf map changes. | 6425 // Fires when the layout of an object with a leaf map changes. |
| 6370 // This includes adding transitions to the leaf map or changing | 6426 // This includes adding transitions to the leaf map or changing |
| 6371 // the descriptor array. | 6427 // the descriptor array. |
| 6372 inline void NotifyLeafMapLayoutChange(); | 6428 inline void NotifyLeafMapLayoutChange(); |
| 6373 | 6429 |
| 6374 static Handle<Map> TransitionElementsToSlow(Handle<Map> object, | 6430 static Handle<Map> TransitionElementsToSlow(Handle<Map> object, |
| 6375 ElementsKind to_kind); | 6431 ElementsKind to_kind); |
| 6376 | 6432 |
| 6433 // Zaps the contents of backing data structures. Note that the |
| 6434 // heap verifier (i.e. VerifyMarkingVisitor) relies on zapping of objects |
| 6435 // holding weak references when incremental marking is used, because it also |
| 6436 // iterates over objects that are otherwise unreachable. |
| 6437 // In general we only want to call these functions in release mode when |
| 6438 // heap verification is turned on. |
| 6439 void ZapPrototypeTransitions(); |
| 6440 void ZapTransitions(); |
| 6441 |
| 6377 void DeprecateTransitionTree(); | 6442 void DeprecateTransitionTree(); |
| 6378 bool DeprecateTarget(PropertyKind kind, Name* key, | 6443 bool DeprecateTarget(PropertyKind kind, Name* key, |
| 6379 PropertyAttributes attributes, | 6444 PropertyAttributes attributes, |
| 6380 DescriptorArray* new_descriptors, | 6445 DescriptorArray* new_descriptors, |
| 6381 LayoutDescriptor* new_layout_descriptor); | 6446 LayoutDescriptor* new_layout_descriptor); |
| 6382 | 6447 |
| 6383 Map* FindLastMatchMap(int verbatim, int length, DescriptorArray* descriptors); | 6448 Map* FindLastMatchMap(int verbatim, int length, DescriptorArray* descriptors); |
| 6384 | 6449 |
| 6385 // Update field type of the given descriptor to new representation and new | 6450 // Update field type of the given descriptor to new representation and new |
| 6386 // type. The type must be prepared for storing in descriptor array: | 6451 // type. The type must be prepared for storing in descriptor array: |
| 6387 // it must be either a simple type or a map wrapped in a weak cell. | 6452 // it must be either a simple type or a map wrapped in a weak cell. |
| 6388 void UpdateFieldType(int descriptor_number, Handle<Name> name, | 6453 void UpdateFieldType(int descriptor_number, Handle<Name> name, |
| 6389 Representation new_representation, | 6454 Representation new_representation, |
| 6390 Handle<Object> new_wrapped_type); | 6455 Handle<Object> new_wrapped_type); |
| 6391 | 6456 |
| 6392 void PrintReconfiguration(FILE* file, int modify_index, PropertyKind kind, | 6457 void PrintReconfiguration(FILE* file, int modify_index, PropertyKind kind, |
| 6393 PropertyAttributes attributes); | 6458 PropertyAttributes attributes); |
| 6394 void PrintGeneralization(FILE* file, | 6459 void PrintGeneralization(FILE* file, |
| 6395 const char* reason, | 6460 const char* reason, |
| 6396 int modify_index, | 6461 int modify_index, |
| 6397 int split, | 6462 int split, |
| 6398 int descriptors, | 6463 int descriptors, |
| 6399 bool constant_to_field, | 6464 bool constant_to_field, |
| 6400 Representation old_representation, | 6465 Representation old_representation, |
| 6401 Representation new_representation, | 6466 Representation new_representation, |
| 6402 HeapType* old_field_type, | 6467 HeapType* old_field_type, |
| 6403 HeapType* new_field_type); | 6468 HeapType* new_field_type); |
| 6404 | 6469 |
| 6470 static inline void SetPrototypeTransitions( |
| 6471 Handle<Map> map, |
| 6472 Handle<FixedArray> prototype_transitions); |
| 6473 |
| 6474 static Handle<Map> GetPrototypeTransition(Handle<Map> map, |
| 6475 Handle<Object> prototype); |
| 6476 static Handle<Map> PutPrototypeTransition(Handle<Map> map, |
| 6477 Handle<Object> prototype, |
| 6478 Handle<Map> target_map); |
| 6479 |
| 6405 static const int kFastPropertiesSoftLimit = 12; | 6480 static const int kFastPropertiesSoftLimit = 12; |
| 6406 static const int kMaxFastProperties = 128; | 6481 static const int kMaxFastProperties = 128; |
| 6407 | 6482 |
| 6408 DISALLOW_IMPLICIT_CONSTRUCTORS(Map); | 6483 DISALLOW_IMPLICIT_CONSTRUCTORS(Map); |
| 6409 }; | 6484 }; |
| 6410 | 6485 |
| 6411 | 6486 |
| 6412 // An abstract superclass, a marker class really, for simple structure classes. | 6487 // An abstract superclass, a marker class really, for simple structure classes. |
| 6413 // It doesn't carry much functionality but allows struct classes to be | 6488 // It doesn't carry much functionality but allows struct classes to be |
| 6414 // identified in the type system. | 6489 // identified in the type system. |
| (...skipping 4493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10908 } else { | 10983 } else { |
| 10909 value &= ~(1 << bit_position); | 10984 value &= ~(1 << bit_position); |
| 10910 } | 10985 } |
| 10911 return value; | 10986 return value; |
| 10912 } | 10987 } |
| 10913 }; | 10988 }; |
| 10914 | 10989 |
| 10915 } } // namespace v8::internal | 10990 } } // namespace v8::internal |
| 10916 | 10991 |
| 10917 #endif // V8_OBJECTS_H_ | 10992 #endif // V8_OBJECTS_H_ |
| OLD | NEW |