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

Side by Side Diff: src/objects.h

Issue 7901016: Basic support for tracking smi-only arrays on ia32. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: fix remaining failing tests Created 9 years, 3 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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 ABSENT = 16 // Used in runtime to indicate a property is absent. 130 ABSENT = 16 // Used in runtime to indicate a property is absent.
131 // ABSENT can never be stored in or returned from a descriptor's attributes 131 // ABSENT can never be stored in or returned from a descriptor's attributes
132 // bitfield. It is only used as a return value meaning the attributes of 132 // bitfield. It is only used as a return value meaning the attributes of
133 // a non-existent property. 133 // a non-existent property.
134 }; 134 };
135 135
136 namespace v8 { 136 namespace v8 {
137 namespace internal { 137 namespace internal {
138 138
139 enum ElementsKind { 139 enum ElementsKind {
140 // The "fast" kind for tagged values. Must be first to make it possible 140 // The "fast" kind for elements that only contain SMI values. Must be first
141 // to efficiently check maps if they have fast elements. 141 // to make it possible to efficiently check maps for this kind.
142 FAST_SMI_ONLY_ELEMENTS,
143
144 // The "fast" kind for tagged values. Must be second to make it possible to
145 // efficiently check maps for this and the FAST_SMI_ONLY_ELEMENTS kind
146 // together at once.
142 FAST_ELEMENTS, 147 FAST_ELEMENTS,
143 148
144 // The "fast" kind for unwrapped, non-tagged double values. 149 // The "fast" kind for unwrapped, non-tagged double values.
145 FAST_DOUBLE_ELEMENTS, 150 FAST_DOUBLE_ELEMENTS,
146 151
147 // The "slow" kind. 152 // The "slow" kind.
148 DICTIONARY_ELEMENTS, 153 DICTIONARY_ELEMENTS,
149 NON_STRICT_ARGUMENTS_ELEMENTS, 154 NON_STRICT_ARGUMENTS_ELEMENTS,
150 // The "fast" kind for external arrays 155 // The "fast" kind for external arrays
151 EXTERNAL_BYTE_ELEMENTS, 156 EXTERNAL_BYTE_ELEMENTS,
152 EXTERNAL_UNSIGNED_BYTE_ELEMENTS, 157 EXTERNAL_UNSIGNED_BYTE_ELEMENTS,
153 EXTERNAL_SHORT_ELEMENTS, 158 EXTERNAL_SHORT_ELEMENTS,
154 EXTERNAL_UNSIGNED_SHORT_ELEMENTS, 159 EXTERNAL_UNSIGNED_SHORT_ELEMENTS,
155 EXTERNAL_INT_ELEMENTS, 160 EXTERNAL_INT_ELEMENTS,
156 EXTERNAL_UNSIGNED_INT_ELEMENTS, 161 EXTERNAL_UNSIGNED_INT_ELEMENTS,
157 EXTERNAL_FLOAT_ELEMENTS, 162 EXTERNAL_FLOAT_ELEMENTS,
158 EXTERNAL_DOUBLE_ELEMENTS, 163 EXTERNAL_DOUBLE_ELEMENTS,
159 EXTERNAL_PIXEL_ELEMENTS, 164 EXTERNAL_PIXEL_ELEMENTS,
160 165
161 // Derived constants from ElementsKind 166 // Derived constants from ElementsKind
162 FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND = EXTERNAL_BYTE_ELEMENTS, 167 FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND = EXTERNAL_BYTE_ELEMENTS,
163 LAST_EXTERNAL_ARRAY_ELEMENTS_KIND = EXTERNAL_PIXEL_ELEMENTS, 168 LAST_EXTERNAL_ARRAY_ELEMENTS_KIND = EXTERNAL_PIXEL_ELEMENTS,
164 FIRST_ELEMENTS_KIND = FAST_ELEMENTS, 169 FIRST_ELEMENTS_KIND = FAST_SMI_ONLY_ELEMENTS,
165 LAST_ELEMENTS_KIND = EXTERNAL_PIXEL_ELEMENTS 170 LAST_ELEMENTS_KIND = EXTERNAL_PIXEL_ELEMENTS
166 }; 171 };
167 172
168 static const int kElementsKindCount = 173 static const int kElementsKindCount =
169 LAST_ELEMENTS_KIND - FIRST_ELEMENTS_KIND + 1; 174 LAST_ELEMENTS_KIND - FIRST_ELEMENTS_KIND + 1;
170 175
171 // PropertyDetails captures type and attributes for a property. 176 // PropertyDetails captures type and attributes for a property.
172 // They are used both in property dictionaries and instance descriptors. 177 // They are used both in property dictionaries and instance descriptors.
173 class PropertyDetails BASE_EMBEDDED { 178 class PropertyDetails BASE_EMBEDDED {
174 public: 179 public:
(...skipping 1233 matching lines...) Expand 10 before | Expand all | Expand 10 after
1408 // EnsureWritableFastElements in this case. 1413 // EnsureWritableFastElements in this case.
1409 // 1414 //
1410 // In the slow mode the elements is either a NumberDictionary, an 1415 // In the slow mode the elements is either a NumberDictionary, an
1411 // ExternalArray, or a FixedArray parameter map for a (non-strict) 1416 // ExternalArray, or a FixedArray parameter map for a (non-strict)
1412 // arguments object. 1417 // arguments object.
1413 DECL_ACCESSORS(elements, FixedArrayBase) 1418 DECL_ACCESSORS(elements, FixedArrayBase)
1414 inline void initialize_elements(); 1419 inline void initialize_elements();
1415 MUST_USE_RESULT inline MaybeObject* ResetElements(); 1420 MUST_USE_RESULT inline MaybeObject* ResetElements();
1416 inline ElementsKind GetElementsKind(); 1421 inline ElementsKind GetElementsKind();
1417 inline ElementsAccessor* GetElementsAccessor(); 1422 inline ElementsAccessor* GetElementsAccessor();
1423 inline bool HasFastSmiOnlyElements();
1418 inline bool HasFastElements(); 1424 inline bool HasFastElements();
1425 // Returns if an object has either FAST_ELEMENT or FAST_SMI_ONLY_ELEMENT
1426 // elements. TODO(danno): Rename HasFastTypeElements to HasFastElements() and
1427 // HasFastElements to HasFastObjectElements.
1428 inline bool HasFastTypeElements();
1419 inline bool HasFastDoubleElements(); 1429 inline bool HasFastDoubleElements();
1430 inline bool HasNonStrictArgumentsElements();
1420 inline bool HasDictionaryElements(); 1431 inline bool HasDictionaryElements();
1421 inline bool HasExternalPixelElements(); 1432 inline bool HasExternalPixelElements();
1422 inline bool HasExternalArrayElements(); 1433 inline bool HasExternalArrayElements();
1423 inline bool HasExternalByteElements(); 1434 inline bool HasExternalByteElements();
1424 inline bool HasExternalUnsignedByteElements(); 1435 inline bool HasExternalUnsignedByteElements();
1425 inline bool HasExternalShortElements(); 1436 inline bool HasExternalShortElements();
1426 inline bool HasExternalUnsignedShortElements(); 1437 inline bool HasExternalUnsignedShortElements();
1427 inline bool HasExternalIntElements(); 1438 inline bool HasExternalIntElements();
1428 inline bool HasExternalUnsignedIntElements(); 1439 inline bool HasExternalUnsignedIntElements();
1429 inline bool HasExternalFloatElements(); 1440 inline bool HasExternalFloatElements();
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1580 // be returned in case no hidden properties object is present and creation was 1591 // be returned in case no hidden properties object is present and creation was
1581 // omitted. 1592 // omitted.
1582 MUST_USE_RESULT MaybeObject* GetIdentityHash(HiddenPropertiesFlag flag); 1593 MUST_USE_RESULT MaybeObject* GetIdentityHash(HiddenPropertiesFlag flag);
1583 1594
1584 MUST_USE_RESULT MaybeObject* DeleteProperty(String* name, DeleteMode mode); 1595 MUST_USE_RESULT MaybeObject* DeleteProperty(String* name, DeleteMode mode);
1585 MUST_USE_RESULT MaybeObject* DeleteElement(uint32_t index, DeleteMode mode); 1596 MUST_USE_RESULT MaybeObject* DeleteElement(uint32_t index, DeleteMode mode);
1586 1597
1587 // Tests for the fast common case for property enumeration. 1598 // Tests for the fast common case for property enumeration.
1588 bool IsSimpleEnum(); 1599 bool IsSimpleEnum();
1589 1600
1601 inline void ValidateSmiOnlyElements();
1602
1603 // Makes sure that this object can contain non-smi Object as elements.
1604 inline MaybeObject* EnsureCanContainNonSmiElements();
1605
1606 // Makes sure that this object can contain the specified elements.
1607 inline MaybeObject* EnsureCanContainElements(Object** elements,
1608 uint32_t count);
1609 inline MaybeObject* EnsureCanContainElements(FixedArray* elements);
1610 MaybeObject* EnsureCanContainElements(Arguments* arguments,
1611 uint32_t first_arg,
1612 uint32_t arg_count);
1613
1590 // Do we want to keep the elements in fast case when increasing the 1614 // Do we want to keep the elements in fast case when increasing the
1591 // capacity? 1615 // capacity?
1592 bool ShouldConvertToSlowElements(int new_capacity); 1616 bool ShouldConvertToSlowElements(int new_capacity);
1593 // Returns true if the backing storage for the slow-case elements of 1617 // Returns true if the backing storage for the slow-case elements of
1594 // this object takes up nearly as much space as a fast-case backing 1618 // this object takes up nearly as much space as a fast-case backing
1595 // storage would. In that case the JSObject should have fast 1619 // storage would. In that case the JSObject should have fast
1596 // elements. 1620 // elements.
1597 bool ShouldConvertToFastElements(); 1621 bool ShouldConvertToFastElements();
1598 // Returns true if the elements of JSObject contains only values that can be 1622 // Returns true if the elements of JSObject contains only values that can be
1599 // represented in a FixedDoubleArray. 1623 // represented in a FixedDoubleArray.
(...skipping 29 matching lines...) Expand all
1629 1653
1630 LocalElementType HasLocalElement(uint32_t index); 1654 LocalElementType HasLocalElement(uint32_t index);
1631 1655
1632 bool HasElementWithInterceptor(JSReceiver* receiver, uint32_t index); 1656 bool HasElementWithInterceptor(JSReceiver* receiver, uint32_t index);
1633 bool HasElementPostInterceptor(JSReceiver* receiver, uint32_t index); 1657 bool HasElementPostInterceptor(JSReceiver* receiver, uint32_t index);
1634 1658
1635 MUST_USE_RESULT MaybeObject* SetFastElement(uint32_t index, 1659 MUST_USE_RESULT MaybeObject* SetFastElement(uint32_t index,
1636 Object* value, 1660 Object* value,
1637 StrictModeFlag strict_mode, 1661 StrictModeFlag strict_mode,
1638 bool check_prototype); 1662 bool check_prototype);
1663
1639 MUST_USE_RESULT MaybeObject* SetDictionaryElement(uint32_t index, 1664 MUST_USE_RESULT MaybeObject* SetDictionaryElement(uint32_t index,
1640 Object* value, 1665 Object* value,
1641 StrictModeFlag strict_mode, 1666 StrictModeFlag strict_mode,
1642 bool check_prototype); 1667 bool check_prototype);
1643 1668
1644 MUST_USE_RESULT MaybeObject* SetFastDoubleElement( 1669 MUST_USE_RESULT MaybeObject* SetFastDoubleElement(
1645 uint32_t index, 1670 uint32_t index,
1646 Object* value, 1671 Object* value,
1647 StrictModeFlag strict_mode, 1672 StrictModeFlag strict_mode,
1648 bool check_prototype = true); 1673 bool check_prototype = true);
1649 1674
1650 // Set the index'th array element. 1675 // Set the index'th array element.
1651 // A Failure object is returned if GC is needed. 1676 // A Failure object is returned if GC is needed.
1652 MUST_USE_RESULT MaybeObject* SetElement(uint32_t index, 1677 MUST_USE_RESULT MaybeObject* SetElement(uint32_t index,
1653 Object* value, 1678 Object* value,
1654 StrictModeFlag strict_mode, 1679 StrictModeFlag strict_mode,
1655 bool check_prototype); 1680 bool check_prototype);
1656 1681
1657 // Returns the index'th element. 1682 // Returns the index'th element.
1658 // The undefined object if index is out of bounds. 1683 // The undefined object if index is out of bounds.
1659 MaybeObject* GetElementWithInterceptor(Object* receiver, uint32_t index); 1684 MaybeObject* GetElementWithInterceptor(Object* receiver, uint32_t index);
1660 1685
1686 enum SetFastElementsCapacityMode {
1687 kAllowSmiOnlyElements,
1688 kDontAllowSmiOnlyElements
1689 };
1690
1661 // Replace the elements' backing store with fast elements of the given 1691 // Replace the elements' backing store with fast elements of the given
1662 // capacity. Update the length for JSArrays. Returns the new backing 1692 // capacity. Update the length for JSArrays. Returns the new backing
1663 // store. 1693 // store.
1664 MUST_USE_RESULT MaybeObject* SetFastElementsCapacityAndLength(int capacity, 1694 MUST_USE_RESULT MaybeObject* SetFastElementsCapacityAndLength(
1665 int length); 1695 int capacity,
1696 int length,
1697 SetFastElementsCapacityMode set_capacity_mode);
1666 MUST_USE_RESULT MaybeObject* SetFastDoubleElementsCapacityAndLength( 1698 MUST_USE_RESULT MaybeObject* SetFastDoubleElementsCapacityAndLength(
1667 int capacity, 1699 int capacity,
1668 int length); 1700 int length);
1669 MUST_USE_RESULT MaybeObject* SetSlowElements(Object* length); 1701 MUST_USE_RESULT MaybeObject* SetSlowElements(Object* length);
1670 1702
1671 // Lookup interceptors are used for handling properties controlled by host 1703 // Lookup interceptors are used for handling properties controlled by host
1672 // objects. 1704 // objects.
1673 inline bool HasNamedInterceptor(); 1705 inline bool HasNamedInterceptor();
1674 inline bool HasIndexedInterceptor(); 1706 inline bool HasIndexedInterceptor();
1675 1707
(...skipping 2277 matching lines...) Expand 10 before | Expand all | Expand 10 after
3953 set_bit_field2((bit_field2() & ~kElementsKindMask) | 3985 set_bit_field2((bit_field2() & ~kElementsKindMask) |
3954 (elements_kind << kElementsKindShift)); 3986 (elements_kind << kElementsKindShift));
3955 ASSERT(this->elements_kind() == elements_kind); 3987 ASSERT(this->elements_kind() == elements_kind);
3956 } 3988 }
3957 3989
3958 inline ElementsKind elements_kind() { 3990 inline ElementsKind elements_kind() {
3959 return static_cast<ElementsKind>( 3991 return static_cast<ElementsKind>(
3960 (bit_field2() & kElementsKindMask) >> kElementsKindShift); 3992 (bit_field2() & kElementsKindMask) >> kElementsKindShift);
3961 } 3993 }
3962 3994
3995 // Tells whether the instance has fast elements that are only Smis.
3996 inline bool has_fast_smi_only_elements() {
3997 return elements_kind() == FAST_SMI_ONLY_ELEMENTS;
3998 }
3999
3963 // Tells whether the instance has fast elements. 4000 // Tells whether the instance has fast elements.
3964 // Equivalent to instance->GetElementsKind() == FAST_ELEMENTS.
3965 inline bool has_fast_elements() { 4001 inline bool has_fast_elements() {
3966 return elements_kind() == FAST_ELEMENTS; 4002 return elements_kind() == FAST_ELEMENTS;
3967 } 4003 }
3968 4004
3969 inline bool has_fast_double_elements() { 4005 inline bool has_fast_double_elements() {
3970 return elements_kind() == FAST_DOUBLE_ELEMENTS; 4006 return elements_kind() == FAST_DOUBLE_ELEMENTS;
3971 } 4007 }
3972 4008
4009 inline bool has_non_strict_arguments_elements() {
4010 return elements_kind() == NON_STRICT_ARGUMENTS_ELEMENTS;
4011 }
4012
3973 inline bool has_external_array_elements() { 4013 inline bool has_external_array_elements() {
3974 ElementsKind kind(elements_kind()); 4014 ElementsKind kind(elements_kind());
3975 return kind >= FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND && 4015 return kind >= FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND &&
3976 kind <= LAST_EXTERNAL_ARRAY_ELEMENTS_KIND; 4016 kind <= LAST_EXTERNAL_ARRAY_ELEMENTS_KIND;
3977 } 4017 }
3978 4018
3979 inline bool has_dictionary_elements() { 4019 inline bool has_dictionary_elements() {
3980 return elements_kind() == DICTIONARY_ELEMENTS; 4020 return elements_kind() == DICTIONARY_ELEMENTS;
3981 } 4021 }
3982 4022
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
4210 static const int kIsUndetectable = 5; 4250 static const int kIsUndetectable = 5;
4211 static const int kHasInstanceCallHandler = 6; 4251 static const int kHasInstanceCallHandler = 6;
4212 static const int kIsAccessCheckNeeded = 7; 4252 static const int kIsAccessCheckNeeded = 7;
4213 4253
4214 // Bit positions for bit field 2 4254 // Bit positions for bit field 2
4215 static const int kIsExtensible = 0; 4255 static const int kIsExtensible = 0;
4216 static const int kFunctionWithPrototype = 1; 4256 static const int kFunctionWithPrototype = 1;
4217 static const int kStringWrapperSafeForDefaultValueOf = 2; 4257 static const int kStringWrapperSafeForDefaultValueOf = 2;
4218 static const int kAttachedToSharedFunctionInfo = 3; 4258 static const int kAttachedToSharedFunctionInfo = 3;
4219 // No bits can be used after kElementsKindFirstBit, they are all reserved for 4259 // No bits can be used after kElementsKindFirstBit, they are all reserved for
4220 // storing ElementKind. for anything other than storing the ElementKind. 4260 // storing ElementKind.
4221 static const int kElementsKindShift = 4; 4261 static const int kElementsKindShift = 4;
4222 static const int kElementsKindBitCount = 4; 4262 static const int kElementsKindBitCount = 4;
4223 4263
4224 // Derived values from bit field 2 4264 // Derived values from bit field 2
4225 static const int kElementsKindMask = (-1 << kElementsKindShift) & 4265 static const int kElementsKindMask = (-1 << kElementsKindShift) &
4226 ((1 << (kElementsKindShift + kElementsKindBitCount)) - 1); 4266 ((1 << (kElementsKindShift + kElementsKindBitCount)) - 1);
4227 static const int8_t kMaximumBitField2FastElementValue = static_cast<int8_t>( 4267 static const int8_t kMaximumBitField2FastElementValue = static_cast<int8_t>(
4228 (FAST_ELEMENTS + 1) << Map::kElementsKindShift) - 1; 4268 (FAST_ELEMENTS + 1) << Map::kElementsKindShift) - 1;
4269 static const int8_t kMaximumBitField2FastSmiOnlyElementValue =
4270 static_cast<int8_t>((FAST_SMI_ONLY_ELEMENTS + 1) <<
4271 Map::kElementsKindShift) - 1;
4229 4272
4230 // Bit positions for bit field 3 4273 // Bit positions for bit field 3
4231 static const int kIsShared = 0; 4274 static const int kIsShared = 0;
4232 4275
4233 // Layout of the default cache. It holds alternating name and code objects. 4276 // Layout of the default cache. It holds alternating name and code objects.
4234 static const int kCodeCacheEntrySize = 2; 4277 static const int kCodeCacheEntrySize = 2;
4235 static const int kCodeCacheEntryNameOffset = 0; 4278 static const int kCodeCacheEntryNameOffset = 0;
4236 static const int kCodeCacheEntryCodeOffset = 1; 4279 static const int kCodeCacheEntryCodeOffset = 1;
4237 4280
4238 typedef FixedBodyDescriptor<kPointerFieldsBeginOffset, 4281 typedef FixedBodyDescriptor<kPointerFieldsBeginOffset,
(...skipping 2572 matching lines...) Expand 10 before | Expand all | Expand 10 after
6811 6854
6812 MUST_USE_RESULT MaybeObject* JSArrayUpdateLengthFromIndex(uint32_t index, 6855 MUST_USE_RESULT MaybeObject* JSArrayUpdateLengthFromIndex(uint32_t index,
6813 Object* value); 6856 Object* value);
6814 6857
6815 // Initialize the array with the given capacity. The function may 6858 // Initialize the array with the given capacity. The function may
6816 // fail due to out-of-memory situations, but only if the requested 6859 // fail due to out-of-memory situations, but only if the requested
6817 // capacity is non-zero. 6860 // capacity is non-zero.
6818 MUST_USE_RESULT MaybeObject* Initialize(int capacity); 6861 MUST_USE_RESULT MaybeObject* Initialize(int capacity);
6819 6862
6820 // Set the content of the array to the content of storage. 6863 // Set the content of the array to the content of storage.
6821 inline void SetContent(FixedArray* storage); 6864 inline MaybeObject* SetContent(FixedArray* storage);
6822 6865
6823 // Casting. 6866 // Casting.
6824 static inline JSArray* cast(Object* obj); 6867 static inline JSArray* cast(Object* obj);
6825 6868
6826 // Uses handles. Ensures that the fixed array backing the JSArray has at 6869 // Uses handles. Ensures that the fixed array backing the JSArray has at
6827 // least the stated size. 6870 // least the stated size.
6828 inline void EnsureSize(int minimum_size_of_backing_fixed_array); 6871 inline void EnsureSize(int minimum_size_of_backing_fixed_array);
6829 6872
6830 // Dispatched behavior. 6873 // Dispatched behavior.
6831 #ifdef OBJECT_PRINT 6874 #ifdef OBJECT_PRINT
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
7391 } else { 7434 } else {
7392 value &= ~(1 << bit_position); 7435 value &= ~(1 << bit_position);
7393 } 7436 }
7394 return value; 7437 return value;
7395 } 7438 }
7396 }; 7439 };
7397 7440
7398 } } // namespace v8::internal 7441 } } // namespace v8::internal
7399 7442
7400 #endif // V8_OBJECTS_H_ 7443 #endif // V8_OBJECTS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698