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

Side by Side Diff: src/objects.h

Issue 10444055: Promoting elements transitions to their own field. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: renaming SearchMode fields and moving it into descriptor array class Created 8 years, 6 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
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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 }; 162 };
163 163
164 164
165 // Indicates whether a get method should implicitly create the object looked up. 165 // Indicates whether a get method should implicitly create the object looked up.
166 enum CreationFlag { 166 enum CreationFlag {
167 ALLOW_CREATION, 167 ALLOW_CREATION,
168 OMIT_CREATION 168 OMIT_CREATION
169 }; 169 };
170 170
171 171
172 // Indicates whether the search function should expect a sorted or an unsorted
173 // descriptor array as input.
danno 2012/06/06 09:25:12 nit: remove the reference to descriptor if you wan
174 enum SearchMode {
175 EXPECT_SORTED,
176 EXPECT_UNSORTED
177 };
178
179
172 // Instance size sentinel for objects of variable size. 180 // Instance size sentinel for objects of variable size.
173 const int kVariableSizeSentinel = 0; 181 const int kVariableSizeSentinel = 0;
174 182
175 183
176 // All Maps have a field instance_type containing a InstanceType. 184 // All Maps have a field instance_type containing a InstanceType.
177 // It describes the type of the instances. 185 // It describes the type of the instances.
178 // 186 //
179 // As an example, a JavaScript object is a heap object and its map 187 // As an example, a JavaScript object is a heap object and its map
180 // instance_type is JS_OBJECT_TYPE. 188 // instance_type is JS_OBJECT_TYPE.
181 // 189 //
(...skipping 2209 matching lines...) Expand 10 before | Expand all | Expand 10 after
2391 // [1]: pointer to fixed array with enum cache 2399 // [1]: pointer to fixed array with enum cache
2392 // [3]: first key 2400 // [3]: first key
2393 // [length() - 1]: last key 2401 // [length() - 1]: last key
2394 // 2402 //
2395 class DescriptorArray: public FixedArray { 2403 class DescriptorArray: public FixedArray {
2396 public: 2404 public:
2397 // Returns true for both shared empty_descriptor_array and for smis, which the 2405 // Returns true for both shared empty_descriptor_array and for smis, which the
2398 // map uses to encode additional bit fields when the descriptor array is not 2406 // map uses to encode additional bit fields when the descriptor array is not
2399 // yet used. 2407 // yet used.
2400 inline bool IsEmpty(); 2408 inline bool IsEmpty();
2409 inline bool MayContainTransitions();
2410
2411 DECL_ACCESSORS(elements_transition_map, Map)
2401 2412
2402 // Returns the number of descriptors in the array. 2413 // Returns the number of descriptors in the array.
2403 int number_of_descriptors() { 2414 int number_of_descriptors() {
2404 ASSERT(length() > kFirstIndex || IsEmpty()); 2415 ASSERT(length() > kFirstIndex ||
2416 length() == kTransitionsIndex ||
2417 IsEmpty());
2405 int len = length(); 2418 int len = length();
2406 return len <= kFirstIndex ? 0 : (len - kFirstIndex) / kDescriptorSize; 2419 return len <= kFirstIndex ? 0 : (len - kFirstIndex) / kDescriptorSize;
2407 } 2420 }
2408 2421
2409 int NextEnumerationIndex() { 2422 int NextEnumerationIndex() {
2410 if (IsEmpty()) return PropertyDetails::kInitialIndex; 2423 if (IsEmpty()) return PropertyDetails::kInitialIndex;
2411 Object* obj = get(kEnumerationIndexIndex); 2424 Object* obj = get(kEnumerationIndexIndex);
2412 if (obj->IsSmi()) { 2425 if (obj->IsSmi()) {
2413 return Smi::cast(obj)->value(); 2426 return Smi::cast(obj)->value();
2414 } else { 2427 } else {
(...skipping 17 matching lines...) Expand all
2432 FixedArray* bridge = FixedArray::cast(get(kEnumerationIndexIndex)); 2445 FixedArray* bridge = FixedArray::cast(get(kEnumerationIndexIndex));
2433 return bridge->get(kEnumCacheBridgeCacheIndex); 2446 return bridge->get(kEnumCacheBridgeCacheIndex);
2434 } 2447 }
2435 2448
2436 Object** GetEnumCacheSlot() { 2449 Object** GetEnumCacheSlot() {
2437 ASSERT(HasEnumCache()); 2450 ASSERT(HasEnumCache());
2438 return HeapObject::RawField(reinterpret_cast<HeapObject*>(this), 2451 return HeapObject::RawField(reinterpret_cast<HeapObject*>(this),
2439 kEnumerationIndexOffset); 2452 kEnumerationIndexOffset);
2440 } 2453 }
2441 2454
2455 Object** GetTransitionsSlot() {
2456 ASSERT(elements_transition_map() != NULL);
2457 return HeapObject::RawField(reinterpret_cast<HeapObject*>(this),
2458 kTransitionsOffset);
2459 }
2460
2442 // TODO(1399): It should be possible to make room for bit_field3 in the map 2461 // TODO(1399): It should be possible to make room for bit_field3 in the map
2443 // without overloading the instance descriptors field in the map 2462 // without overloading the instance descriptors field in the map
2444 // (and storing it in the DescriptorArray when the map has one). 2463 // (and storing it in the DescriptorArray when the map has one).
2445 inline int bit_field3_storage(); 2464 inline int bit_field3_storage();
2446 inline void set_bit_field3_storage(int value); 2465 inline void set_bit_field3_storage(int value);
2447 2466
2448 // Initialize or change the enum cache, 2467 // Initialize or change the enum cache,
2449 // using the supplied storage for the small "bridge". 2468 // using the supplied storage for the small "bridge".
2450 void SetEnumCache(FixedArray* bridge_storage, 2469 void SetEnumCache(FixedArray* bridge_storage,
2451 FixedArray* new_cache, 2470 FixedArray* new_cache,
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
2508 2527
2509 // Copy the descriptor array, insert a new descriptor and optionally 2528 // Copy the descriptor array, insert a new descriptor and optionally
2510 // remove map transitions. If the descriptor is already present, it is 2529 // remove map transitions. If the descriptor is already present, it is
2511 // replaced. If a replaced descriptor is a real property (not a transition 2530 // replaced. If a replaced descriptor is a real property (not a transition
2512 // or null), its enumeration index is kept as is. 2531 // or null), its enumeration index is kept as is.
2513 // If adding a real property, map transitions must be removed. If adding 2532 // If adding a real property, map transitions must be removed. If adding
2514 // a transition, they must not be removed. All null descriptors are removed. 2533 // a transition, they must not be removed. All null descriptors are removed.
2515 MUST_USE_RESULT MaybeObject* CopyInsert(Descriptor* descriptor, 2534 MUST_USE_RESULT MaybeObject* CopyInsert(Descriptor* descriptor,
2516 TransitionFlag transition_flag); 2535 TransitionFlag transition_flag);
2517 2536
2537 // Indicates whether the search function should expect a sorted or an unsorted
2538 // descriptor array as input.
2539 enum SharedMode {
2540 MAY_BE_SHARED,
2541 CANNOT_BE_SHARED
2542 };
2543
2518 // Return a copy of the array with all transitions and null descriptors 2544 // Return a copy of the array with all transitions and null descriptors
2519 // removed. Return a Failure object in case of an allocation failure. 2545 // removed. Return a Failure object in case of an allocation failure.
2520 MUST_USE_RESULT MaybeObject* RemoveTransitions(); 2546 MUST_USE_RESULT MaybeObject* RemoveTransitions(SharedMode shared_mode);
2521 2547
2522 // Sort the instance descriptors by the hash codes of their keys. 2548 // Sort the instance descriptors by the hash codes of their keys.
2523 // Does not check for duplicates. 2549 // Does not check for duplicates.
2524 void SortUnchecked(const WhitenessWitness&); 2550 void SortUnchecked(const WhitenessWitness&);
2525 2551
2526 // Sort the instance descriptors by the hash codes of their keys. 2552 // Sort the instance descriptors by the hash codes of their keys.
2527 // Checks the result for duplicates. 2553 // Checks the result for duplicates.
2528 void Sort(const WhitenessWitness&); 2554 void Sort(const WhitenessWitness&);
2529 2555
2530 // Search the instance descriptors for given name. 2556 // Search the instance descriptors for given name.
2531 inline int Search(String* name); 2557 inline int Search(String* name);
2532 2558
2533 // As the above, but uses DescriptorLookupCache and updates it when 2559 // As the above, but uses DescriptorLookupCache and updates it when
2534 // necessary. 2560 // necessary.
2535 inline int SearchWithCache(String* name); 2561 inline int SearchWithCache(String* name);
2536 2562
2537 // Tells whether the name is present int the array. 2563 // Tells whether the name is present int the array.
2538 bool Contains(String* name) { return kNotFound != Search(name); } 2564 bool Contains(String* name) { return kNotFound != Search(name); }
2539 2565
2540 // Perform a binary search in the instance descriptors represented 2566 // Perform a binary search in the instance descriptors represented
2541 // by this fixed array. low and high are descriptor indices. If there 2567 // by this fixed array. low and high are descriptor indices. If there
2542 // are three instance descriptors in this array it should be called 2568 // are three instance descriptors in this array it should be called
2543 // with low=0 and high=2. 2569 // with low=0 and high=2.
2544 int BinarySearch(String* name, int low, int high); 2570 int BinarySearch(String* name, int low, int high);
2545 2571
2546 // Perform a linear search in the instance descriptors represented 2572 // Perform a linear search in the instance descriptors represented
2547 // by this fixed array. len is the number of descriptor indices that are 2573 // by this fixed array. len is the number of descriptor indices that are
2548 // valid. Does not require the descriptors to be sorted. 2574 // valid.
2549 int LinearSearch(String* name, int len); 2575 int LinearSearch(SearchMode mode, String* name, int len);
2550 2576
2551 // Allocates a DescriptorArray, but returns the singleton 2577 // Allocates a DescriptorArray, but returns the singleton
2552 // empty descriptor array object if number_of_descriptors is 0. 2578 // empty descriptor array object if number_of_descriptors is 0.
2553 MUST_USE_RESULT static MaybeObject* Allocate(int number_of_descriptors); 2579 MUST_USE_RESULT static MaybeObject* Allocate(int number_of_descriptors,
2580 SharedMode shared_mode);
2554 2581
2555 // Casting. 2582 // Casting.
2556 static inline DescriptorArray* cast(Object* obj); 2583 static inline DescriptorArray* cast(Object* obj);
2557 2584
2558 // Constant for denoting key was not found. 2585 // Constant for denoting key was not found.
2559 static const int kNotFound = -1; 2586 static const int kNotFound = -1;
2560 2587
2561 static const int kBitField3StorageIndex = 0; 2588 static const int kBitField3StorageIndex = 0;
2562 static const int kEnumerationIndexIndex = 1; 2589 static const int kTransitionsIndex = 1;
2563 static const int kFirstIndex = 2; 2590 static const int kEnumerationIndexIndex = 2;
2591 static const int kFirstIndex = 3;
2564 2592
2565 // The length of the "bridge" to the enum cache. 2593 // The length of the "bridge" to the enum cache.
2566 static const int kEnumCacheBridgeLength = 3; 2594 static const int kEnumCacheBridgeLength = 3;
2567 static const int kEnumCacheBridgeEnumIndex = 0; 2595 static const int kEnumCacheBridgeEnumIndex = 0;
2568 static const int kEnumCacheBridgeCacheIndex = 1; 2596 static const int kEnumCacheBridgeCacheIndex = 1;
2569 static const int kEnumCacheBridgeIndicesCacheIndex = 2; 2597 static const int kEnumCacheBridgeIndicesCacheIndex = 2;
2570 2598
2571 // Layout description. 2599 // Layout description.
2572 static const int kBitField3StorageOffset = FixedArray::kHeaderSize; 2600 static const int kBitField3StorageOffset = FixedArray::kHeaderSize;
2573 static const int kEnumerationIndexOffset = kBitField3StorageOffset + 2601 static const int kTransitionsOffset = kBitField3StorageOffset + kPointerSize;
2574 kPointerSize; 2602 static const int kEnumerationIndexOffset = kTransitionsOffset + kPointerSize;
2575 static const int kFirstOffset = kEnumerationIndexOffset + kPointerSize; 2603 static const int kFirstOffset = kEnumerationIndexOffset + kPointerSize;
2576 2604
2577 // Layout description for the bridge array. 2605 // Layout description for the bridge array.
2578 static const int kEnumCacheBridgeEnumOffset = FixedArray::kHeaderSize; 2606 static const int kEnumCacheBridgeEnumOffset = FixedArray::kHeaderSize;
2579 static const int kEnumCacheBridgeCacheOffset = 2607 static const int kEnumCacheBridgeCacheOffset =
2580 kEnumCacheBridgeEnumOffset + kPointerSize; 2608 kEnumCacheBridgeEnumOffset + kPointerSize;
2581 2609
2582 // Layout of descriptor. 2610 // Layout of descriptor.
2583 static const int kDescriptorKey = 0; 2611 static const int kDescriptorKey = 0;
2584 static const int kDescriptorDetails = 1; 2612 static const int kDescriptorDetails = 1;
(...skipping 2085 matching lines...) Expand 10 before | Expand all | Expand 10 after
4670 } 4698 }
4671 4699
4672 inline bool has_slow_elements_kind() { 4700 inline bool has_slow_elements_kind() {
4673 return elements_kind() == DICTIONARY_ELEMENTS 4701 return elements_kind() == DICTIONARY_ELEMENTS
4674 || elements_kind() == NON_STRICT_ARGUMENTS_ELEMENTS; 4702 || elements_kind() == NON_STRICT_ARGUMENTS_ELEMENTS;
4675 } 4703 }
4676 4704
4677 static bool IsValidElementsTransition(ElementsKind from_kind, 4705 static bool IsValidElementsTransition(ElementsKind from_kind,
4678 ElementsKind to_kind); 4706 ElementsKind to_kind);
4679 4707
4708 inline Map* elements_transition_map();
4709 inline void set_elements_transition_map(Map* transitioned_map);
4710
4680 // Tells whether the map is attached to SharedFunctionInfo 4711 // Tells whether the map is attached to SharedFunctionInfo
4681 // (for inobject slack tracking). 4712 // (for inobject slack tracking).
4682 inline void set_attached_to_shared_function_info(bool value); 4713 inline void set_attached_to_shared_function_info(bool value);
4683 4714
4684 inline bool attached_to_shared_function_info(); 4715 inline bool attached_to_shared_function_info();
4685 4716
4686 // Tells whether the map is shared between objects that may have different 4717 // Tells whether the map is shared between objects that may have different
4687 // behavior. If true, the map should never be modified, instead a clone 4718 // behavior. If true, the map should never be modified, instead a clone
4688 // should be created and modified. 4719 // should be created and modified.
4689 inline void set_is_shared(bool value); 4720 inline void set_is_shared(bool value);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
4766 String* name, 4797 String* name,
4767 LookupResult* result); 4798 LookupResult* result);
4768 4799
4769 MUST_USE_RESULT MaybeObject* CopyDropDescriptors(); 4800 MUST_USE_RESULT MaybeObject* CopyDropDescriptors();
4770 4801
4771 MUST_USE_RESULT MaybeObject* CopyNormalized(PropertyNormalizationMode mode, 4802 MUST_USE_RESULT MaybeObject* CopyNormalized(PropertyNormalizationMode mode,
4772 NormalizedMapSharingMode sharing); 4803 NormalizedMapSharingMode sharing);
4773 4804
4774 // Returns a copy of the map, with all transitions dropped from the 4805 // Returns a copy of the map, with all transitions dropped from the
4775 // instance descriptors. 4806 // instance descriptors.
4776 MUST_USE_RESULT MaybeObject* CopyDropTransitions(); 4807 MUST_USE_RESULT MaybeObject* CopyDropTransitions(
4808 DescriptorArray::SharedMode shared_mode);
4777 4809
4778 // Returns the property index for name (only valid for FAST MODE). 4810 // Returns the property index for name (only valid for FAST MODE).
4779 int PropertyIndexFor(String* name); 4811 int PropertyIndexFor(String* name);
4780 4812
4781 // Returns the next free property index (only valid for FAST MODE). 4813 // Returns the next free property index (only valid for FAST MODE).
4782 int NextFreePropertyIndex(); 4814 int NextFreePropertyIndex();
4783 4815
4784 // Returns the number of properties described in instance_descriptors 4816 // Returns the number of properties described in instance_descriptors
4785 // filtering out properties with the specified attributes. 4817 // filtering out properties with the specified attributes.
4786 int NumberOfDescribedProperties(PropertyAttributes filter = NONE); 4818 int NumberOfDescribedProperties(PropertyAttributes filter = NONE);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
4819 4851
4820 // Computes a hash value for this map, to be used in HashTables and such. 4852 // Computes a hash value for this map, to be used in HashTables and such.
4821 int Hash(); 4853 int Hash();
4822 4854
4823 // Compares this map to another to see if they describe equivalent objects. 4855 // Compares this map to another to see if they describe equivalent objects.
4824 // If |mode| is set to CLEAR_INOBJECT_PROPERTIES, |other| is treated as if 4856 // If |mode| is set to CLEAR_INOBJECT_PROPERTIES, |other| is treated as if
4825 // it had exactly zero inobject properties. 4857 // it had exactly zero inobject properties.
4826 // The "shared" flags of both this map and |other| are ignored. 4858 // The "shared" flags of both this map and |other| are ignored.
4827 bool EquivalentToForNormalization(Map* other, PropertyNormalizationMode mode); 4859 bool EquivalentToForNormalization(Map* other, PropertyNormalizationMode mode);
4828 4860
4829 // Returns the contents of this map's descriptor array for the given string.
4830 // May return NULL. |safe_to_add_transition| is set to false and NULL
4831 // is returned if adding transitions is not allowed.
4832 Object* GetDescriptorContents(String* sentinel_name,
4833 bool* safe_to_add_transitions);
4834
4835 // Returns the map that this map transitions to if its elements_kind 4861 // Returns the map that this map transitions to if its elements_kind
4836 // is changed to |elements_kind|, or NULL if no such map is cached yet. 4862 // is changed to |elements_kind|, or NULL if no such map is cached yet.
4837 // |safe_to_add_transitions| is set to false if adding transitions is not 4863 // |safe_to_add_transitions| is set to false if adding transitions is not
4838 // allowed. 4864 // allowed.
4839 Map* LookupElementsTransitionMap(ElementsKind elements_kind, 4865 Map* LookupElementsTransitionMap(ElementsKind elements_kind);
4840 bool* safe_to_add_transition);
4841 4866
4842 // Adds an entry to this map's descriptor array for a transition to 4867 // Adds a new transitions for changing the elements kind to |elements_kind|.
4843 // |transitioned_map| when its elements_kind is changed to |elements_kind|. 4868 MUST_USE_RESULT MaybeObject* CreateNextElementsTransition(
4844 MUST_USE_RESULT MaybeObject* AddElementsTransition( 4869 ElementsKind elements_kind);
4845 ElementsKind elements_kind, Map* transitioned_map);
4846 4870
4847 // Returns the transitioned map for this map with the most generic 4871 // Returns the transitioned map for this map with the most generic
4848 // elements_kind that's found in |candidates|, or null handle if no match is 4872 // elements_kind that's found in |candidates|, or null handle if no match is
4849 // found at all. 4873 // found at all.
4850 Handle<Map> FindTransitionedMap(MapHandleList* candidates); 4874 Handle<Map> FindTransitionedMap(MapHandleList* candidates);
4851 Map* FindTransitionedMap(MapList* candidates); 4875 Map* FindTransitionedMap(MapList* candidates);
4852 4876
4853 // Zaps the contents of backing data structures in debug mode. Note that the 4877 // Zaps the contents of backing data structures in debug mode. Note that the
4854 // heap verifier (i.e. VerifyMarkingVisitor) relies on zapping of objects 4878 // heap verifier (i.e. VerifyMarkingVisitor) relies on zapping of objects
4855 // holding weak references when incremental marking is used, because it also 4879 // holding weak references when incremental marking is used, because it also
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
4977 // Layout of the default cache. It holds alternating name and code objects. 5001 // Layout of the default cache. It holds alternating name and code objects.
4978 static const int kCodeCacheEntrySize = 2; 5002 static const int kCodeCacheEntrySize = 2;
4979 static const int kCodeCacheEntryNameOffset = 0; 5003 static const int kCodeCacheEntryNameOffset = 0;
4980 static const int kCodeCacheEntryCodeOffset = 1; 5004 static const int kCodeCacheEntryCodeOffset = 1;
4981 5005
4982 typedef FixedBodyDescriptor<kPointerFieldsBeginOffset, 5006 typedef FixedBodyDescriptor<kPointerFieldsBeginOffset,
4983 kPointerFieldsEndOffset, 5007 kPointerFieldsEndOffset,
4984 kSize> BodyDescriptor; 5008 kSize> BodyDescriptor;
4985 5009
4986 private: 5010 private:
4987 String* elements_transition_sentinel_name();
4988 DISALLOW_IMPLICIT_CONSTRUCTORS(Map); 5011 DISALLOW_IMPLICIT_CONSTRUCTORS(Map);
4989 }; 5012 };
4990 5013
4991 5014
4992 // An abstract superclass, a marker class really, for simple structure classes. 5015 // An abstract superclass, a marker class really, for simple structure classes.
4993 // It doesn't carry much functionality but allows struct classes to be 5016 // It doesn't carry much functionality but allows struct classes to be
4994 // identified in the type system. 5017 // identified in the type system.
4995 class Struct: public HeapObject { 5018 class Struct: public HeapObject {
4996 public: 5019 public:
4997 inline void InitializeBody(int object_size); 5020 inline void InitializeBody(int object_size);
(...skipping 3680 matching lines...) Expand 10 before | Expand all | Expand 10 after
8678 } else { 8701 } else {
8679 value &= ~(1 << bit_position); 8702 value &= ~(1 << bit_position);
8680 } 8703 }
8681 return value; 8704 return value;
8682 } 8705 }
8683 }; 8706 };
8684 8707
8685 } } // namespace v8::internal 8708 } } // namespace v8::internal
8686 8709
8687 #endif // V8_OBJECTS_H_ 8710 #endif // V8_OBJECTS_H_
OLDNEW
« no previous file with comments | « src/mips/macro-assembler-mips.cc ('k') | src/objects.cc » ('j') | src/objects.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698