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

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: ready to land 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 1250 matching lines...) Expand 10 before | Expand all | Expand 10 after
1425 // EnsureWritableFastElements in this case. 1430 // EnsureWritableFastElements in this case.
1426 // 1431 //
1427 // In the slow mode the elements is either a NumberDictionary, an 1432 // In the slow mode the elements is either a NumberDictionary, an
1428 // ExternalArray, or a FixedArray parameter map for a (non-strict) 1433 // ExternalArray, or a FixedArray parameter map for a (non-strict)
1429 // arguments object. 1434 // arguments object.
1430 DECL_ACCESSORS(elements, FixedArrayBase) 1435 DECL_ACCESSORS(elements, FixedArrayBase)
1431 inline void initialize_elements(); 1436 inline void initialize_elements();
1432 MUST_USE_RESULT inline MaybeObject* ResetElements(); 1437 MUST_USE_RESULT inline MaybeObject* ResetElements();
1433 inline ElementsKind GetElementsKind(); 1438 inline ElementsKind GetElementsKind();
1434 inline ElementsAccessor* GetElementsAccessor(); 1439 inline ElementsAccessor* GetElementsAccessor();
1440 inline bool HasFastSmiOnlyElements();
1435 inline bool HasFastElements(); 1441 inline bool HasFastElements();
1442 // Returns if an object has either FAST_ELEMENT or FAST_SMI_ONLY_ELEMENT
1443 // elements. TODO(danno): Rename HasFastTypeElements to HasFastElements() and
1444 // HasFastElements to HasFastObjectElements.
1445 inline bool HasFastTypeElements();
1436 inline bool HasFastDoubleElements(); 1446 inline bool HasFastDoubleElements();
1447 inline bool HasNonStrictArgumentsElements();
1437 inline bool HasDictionaryElements(); 1448 inline bool HasDictionaryElements();
1438 inline bool HasExternalPixelElements(); 1449 inline bool HasExternalPixelElements();
1439 inline bool HasExternalArrayElements(); 1450 inline bool HasExternalArrayElements();
1440 inline bool HasExternalByteElements(); 1451 inline bool HasExternalByteElements();
1441 inline bool HasExternalUnsignedByteElements(); 1452 inline bool HasExternalUnsignedByteElements();
1442 inline bool HasExternalShortElements(); 1453 inline bool HasExternalShortElements();
1443 inline bool HasExternalUnsignedShortElements(); 1454 inline bool HasExternalUnsignedShortElements();
1444 inline bool HasExternalIntElements(); 1455 inline bool HasExternalIntElements();
1445 inline bool HasExternalUnsignedIntElements(); 1456 inline bool HasExternalUnsignedIntElements();
1446 inline bool HasExternalFloatElements(); 1457 inline bool HasExternalFloatElements();
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1601 // be returned in case no hidden properties object is present and creation was 1612 // be returned in case no hidden properties object is present and creation was
1602 // omitted. 1613 // omitted.
1603 MUST_USE_RESULT MaybeObject* GetIdentityHash(HiddenPropertiesFlag flag); 1614 MUST_USE_RESULT MaybeObject* GetIdentityHash(HiddenPropertiesFlag flag);
1604 1615
1605 MUST_USE_RESULT MaybeObject* DeleteProperty(String* name, DeleteMode mode); 1616 MUST_USE_RESULT MaybeObject* DeleteProperty(String* name, DeleteMode mode);
1606 MUST_USE_RESULT MaybeObject* DeleteElement(uint32_t index, DeleteMode mode); 1617 MUST_USE_RESULT MaybeObject* DeleteElement(uint32_t index, DeleteMode mode);
1607 1618
1608 // Tests for the fast common case for property enumeration. 1619 // Tests for the fast common case for property enumeration.
1609 bool IsSimpleEnum(); 1620 bool IsSimpleEnum();
1610 1621
1622 inline void ValidateSmiOnlyElements();
1623
1624 // Makes sure that this object can contain non-smi Object as elements.
1625 inline MaybeObject* EnsureCanContainNonSmiElements();
1626
1627 // Makes sure that this object can contain the specified elements.
1628 inline MaybeObject* EnsureCanContainElements(Object** elements,
1629 uint32_t count);
1630 inline MaybeObject* EnsureCanContainElements(FixedArray* elements);
1631 MaybeObject* EnsureCanContainElements(Arguments* arguments,
1632 uint32_t first_arg,
1633 uint32_t arg_count);
1634
1611 // Do we want to keep the elements in fast case when increasing the 1635 // Do we want to keep the elements in fast case when increasing the
1612 // capacity? 1636 // capacity?
1613 bool ShouldConvertToSlowElements(int new_capacity); 1637 bool ShouldConvertToSlowElements(int new_capacity);
1614 // Returns true if the backing storage for the slow-case elements of 1638 // Returns true if the backing storage for the slow-case elements of
1615 // this object takes up nearly as much space as a fast-case backing 1639 // this object takes up nearly as much space as a fast-case backing
1616 // storage would. In that case the JSObject should have fast 1640 // storage would. In that case the JSObject should have fast
1617 // elements. 1641 // elements.
1618 bool ShouldConvertToFastElements(); 1642 bool ShouldConvertToFastElements();
1619 // Returns true if the elements of JSObject contains only values that can be 1643 // Returns true if the elements of JSObject contains only values that can be
1620 // represented in a FixedDoubleArray. 1644 // represented in a FixedDoubleArray.
(...skipping 28 matching lines...) Expand all
1649 1673
1650 LocalElementType HasLocalElement(uint32_t index); 1674 LocalElementType HasLocalElement(uint32_t index);
1651 1675
1652 bool HasElementWithInterceptor(JSReceiver* receiver, uint32_t index); 1676 bool HasElementWithInterceptor(JSReceiver* receiver, uint32_t index);
1653 bool HasElementPostInterceptor(JSReceiver* receiver, uint32_t index); 1677 bool HasElementPostInterceptor(JSReceiver* receiver, uint32_t index);
1654 1678
1655 MUST_USE_RESULT MaybeObject* SetFastElement(uint32_t index, 1679 MUST_USE_RESULT MaybeObject* SetFastElement(uint32_t index,
1656 Object* value, 1680 Object* value,
1657 StrictModeFlag strict_mode, 1681 StrictModeFlag strict_mode,
1658 bool check_prototype); 1682 bool check_prototype);
1683
1659 MUST_USE_RESULT MaybeObject* SetDictionaryElement(uint32_t index, 1684 MUST_USE_RESULT MaybeObject* SetDictionaryElement(uint32_t index,
1660 Object* value, 1685 Object* value,
1661 StrictModeFlag strict_mode, 1686 StrictModeFlag strict_mode,
1662 bool check_prototype); 1687 bool check_prototype);
1663 1688
1664 MUST_USE_RESULT MaybeObject* SetFastDoubleElement( 1689 MUST_USE_RESULT MaybeObject* SetFastDoubleElement(
1665 uint32_t index, 1690 uint32_t index,
1666 Object* value, 1691 Object* value,
1667 StrictModeFlag strict_mode, 1692 StrictModeFlag strict_mode,
1668 bool check_prototype = true); 1693 bool check_prototype = true);
1669 1694
1670 // Set the index'th array element. 1695 // Set the index'th array element.
1671 // A Failure object is returned if GC is needed. 1696 // A Failure object is returned if GC is needed.
1672 MUST_USE_RESULT MaybeObject* SetElement(uint32_t index, 1697 MUST_USE_RESULT MaybeObject* SetElement(uint32_t index,
1673 Object* value, 1698 Object* value,
1674 StrictModeFlag strict_mode, 1699 StrictModeFlag strict_mode,
1675 bool check_prototype); 1700 bool check_prototype);
1676 1701
1677 // Returns the index'th element. 1702 // Returns the index'th element.
1678 // The undefined object if index is out of bounds. 1703 // The undefined object if index is out of bounds.
1679 MaybeObject* GetElementWithInterceptor(Object* receiver, uint32_t index); 1704 MaybeObject* GetElementWithInterceptor(Object* receiver, uint32_t index);
1680 1705
1706 enum SetFastElementsCapacityMode {
1707 kAllowSmiOnlyElements,
1708 kDontAllowSmiOnlyElements
1709 };
1710
1681 // Replace the elements' backing store with fast elements of the given 1711 // Replace the elements' backing store with fast elements of the given
1682 // capacity. Update the length for JSArrays. Returns the new backing 1712 // capacity. Update the length for JSArrays. Returns the new backing
1683 // store. 1713 // store.
1684 MUST_USE_RESULT MaybeObject* SetFastElementsCapacityAndLength(int capacity, 1714 MUST_USE_RESULT MaybeObject* SetFastElementsCapacityAndLength(
1685 int length); 1715 int capacity,
1716 int length,
1717 SetFastElementsCapacityMode set_capacity_mode);
1686 MUST_USE_RESULT MaybeObject* SetFastDoubleElementsCapacityAndLength( 1718 MUST_USE_RESULT MaybeObject* SetFastDoubleElementsCapacityAndLength(
1687 int capacity, 1719 int capacity,
1688 int length); 1720 int length);
1689 MUST_USE_RESULT MaybeObject* SetSlowElements(Object* length); 1721 MUST_USE_RESULT MaybeObject* SetSlowElements(Object* length);
1690 1722
1691 // Lookup interceptors are used for handling properties controlled by host 1723 // Lookup interceptors are used for handling properties controlled by host
1692 // objects. 1724 // objects.
1693 inline bool HasNamedInterceptor(); 1725 inline bool HasNamedInterceptor();
1694 inline bool HasIndexedInterceptor(); 1726 inline bool HasIndexedInterceptor();
1695 1727
(...skipping 2277 matching lines...) Expand 10 before | Expand all | Expand 10 after
3973 set_bit_field2((bit_field2() & ~kElementsKindMask) | 4005 set_bit_field2((bit_field2() & ~kElementsKindMask) |
3974 (elements_kind << kElementsKindShift)); 4006 (elements_kind << kElementsKindShift));
3975 ASSERT(this->elements_kind() == elements_kind); 4007 ASSERT(this->elements_kind() == elements_kind);
3976 } 4008 }
3977 4009
3978 inline ElementsKind elements_kind() { 4010 inline ElementsKind elements_kind() {
3979 return static_cast<ElementsKind>( 4011 return static_cast<ElementsKind>(
3980 (bit_field2() & kElementsKindMask) >> kElementsKindShift); 4012 (bit_field2() & kElementsKindMask) >> kElementsKindShift);
3981 } 4013 }
3982 4014
4015 // Tells whether the instance has fast elements that are only Smis.
4016 inline bool has_fast_smi_only_elements() {
4017 return elements_kind() == FAST_SMI_ONLY_ELEMENTS;
4018 }
4019
3983 // Tells whether the instance has fast elements. 4020 // Tells whether the instance has fast elements.
3984 // Equivalent to instance->GetElementsKind() == FAST_ELEMENTS.
3985 inline bool has_fast_elements() { 4021 inline bool has_fast_elements() {
3986 return elements_kind() == FAST_ELEMENTS; 4022 return elements_kind() == FAST_ELEMENTS;
3987 } 4023 }
3988 4024
3989 inline bool has_fast_double_elements() { 4025 inline bool has_fast_double_elements() {
3990 return elements_kind() == FAST_DOUBLE_ELEMENTS; 4026 return elements_kind() == FAST_DOUBLE_ELEMENTS;
3991 } 4027 }
3992 4028
4029 inline bool has_non_strict_arguments_elements() {
4030 return elements_kind() == NON_STRICT_ARGUMENTS_ELEMENTS;
4031 }
4032
3993 inline bool has_external_array_elements() { 4033 inline bool has_external_array_elements() {
3994 ElementsKind kind(elements_kind()); 4034 ElementsKind kind(elements_kind());
3995 return kind >= FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND && 4035 return kind >= FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND &&
3996 kind <= LAST_EXTERNAL_ARRAY_ELEMENTS_KIND; 4036 kind <= LAST_EXTERNAL_ARRAY_ELEMENTS_KIND;
3997 } 4037 }
3998 4038
3999 inline bool has_dictionary_elements() { 4039 inline bool has_dictionary_elements() {
4000 return elements_kind() == DICTIONARY_ELEMENTS; 4040 return elements_kind() == DICTIONARY_ELEMENTS;
4001 } 4041 }
4002 4042
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
4230 static const int kIsUndetectable = 5; 4270 static const int kIsUndetectable = 5;
4231 static const int kHasInstanceCallHandler = 6; 4271 static const int kHasInstanceCallHandler = 6;
4232 static const int kIsAccessCheckNeeded = 7; 4272 static const int kIsAccessCheckNeeded = 7;
4233 4273
4234 // Bit positions for bit field 2 4274 // Bit positions for bit field 2
4235 static const int kIsExtensible = 0; 4275 static const int kIsExtensible = 0;
4236 static const int kFunctionWithPrototype = 1; 4276 static const int kFunctionWithPrototype = 1;
4237 static const int kStringWrapperSafeForDefaultValueOf = 2; 4277 static const int kStringWrapperSafeForDefaultValueOf = 2;
4238 static const int kAttachedToSharedFunctionInfo = 3; 4278 static const int kAttachedToSharedFunctionInfo = 3;
4239 // No bits can be used after kElementsKindFirstBit, they are all reserved for 4279 // No bits can be used after kElementsKindFirstBit, they are all reserved for
4240 // storing ElementKind. for anything other than storing the ElementKind. 4280 // storing ElementKind.
4241 static const int kElementsKindShift = 4; 4281 static const int kElementsKindShift = 4;
4242 static const int kElementsKindBitCount = 4; 4282 static const int kElementsKindBitCount = 4;
4243 4283
4244 // Derived values from bit field 2 4284 // Derived values from bit field 2
4245 static const int kElementsKindMask = (-1 << kElementsKindShift) & 4285 static const int kElementsKindMask = (-1 << kElementsKindShift) &
4246 ((1 << (kElementsKindShift + kElementsKindBitCount)) - 1); 4286 ((1 << (kElementsKindShift + kElementsKindBitCount)) - 1);
4247 static const int8_t kMaximumBitField2FastElementValue = static_cast<int8_t>( 4287 static const int8_t kMaximumBitField2FastElementValue = static_cast<int8_t>(
4248 (FAST_ELEMENTS + 1) << Map::kElementsKindShift) - 1; 4288 (FAST_ELEMENTS + 1) << Map::kElementsKindShift) - 1;
4289 static const int8_t kMaximumBitField2FastSmiOnlyElementValue =
4290 static_cast<int8_t>((FAST_SMI_ONLY_ELEMENTS + 1) <<
4291 Map::kElementsKindShift) - 1;
4249 4292
4250 // Bit positions for bit field 3 4293 // Bit positions for bit field 3
4251 static const int kIsShared = 0; 4294 static const int kIsShared = 0;
4252 4295
4253 // Layout of the default cache. It holds alternating name and code objects. 4296 // Layout of the default cache. It holds alternating name and code objects.
4254 static const int kCodeCacheEntrySize = 2; 4297 static const int kCodeCacheEntrySize = 2;
4255 static const int kCodeCacheEntryNameOffset = 0; 4298 static const int kCodeCacheEntryNameOffset = 0;
4256 static const int kCodeCacheEntryCodeOffset = 1; 4299 static const int kCodeCacheEntryCodeOffset = 1;
4257 4300
4258 typedef FixedBodyDescriptor<kPointerFieldsBeginOffset, 4301 typedef FixedBodyDescriptor<kPointerFieldsBeginOffset,
(...skipping 2595 matching lines...) Expand 10 before | Expand all | Expand 10 after
6854 6897
6855 MUST_USE_RESULT MaybeObject* JSArrayUpdateLengthFromIndex(uint32_t index, 6898 MUST_USE_RESULT MaybeObject* JSArrayUpdateLengthFromIndex(uint32_t index,
6856 Object* value); 6899 Object* value);
6857 6900
6858 // Initialize the array with the given capacity. The function may 6901 // Initialize the array with the given capacity. The function may
6859 // fail due to out-of-memory situations, but only if the requested 6902 // fail due to out-of-memory situations, but only if the requested
6860 // capacity is non-zero. 6903 // capacity is non-zero.
6861 MUST_USE_RESULT MaybeObject* Initialize(int capacity); 6904 MUST_USE_RESULT MaybeObject* Initialize(int capacity);
6862 6905
6863 // Set the content of the array to the content of storage. 6906 // Set the content of the array to the content of storage.
6864 inline void SetContent(FixedArray* storage); 6907 inline MaybeObject* SetContent(FixedArray* storage);
6865 6908
6866 // Casting. 6909 // Casting.
6867 static inline JSArray* cast(Object* obj); 6910 static inline JSArray* cast(Object* obj);
6868 6911
6869 // Uses handles. Ensures that the fixed array backing the JSArray has at 6912 // Uses handles. Ensures that the fixed array backing the JSArray has at
6870 // least the stated size. 6913 // least the stated size.
6871 inline void EnsureSize(int minimum_size_of_backing_fixed_array); 6914 inline void EnsureSize(int minimum_size_of_backing_fixed_array);
6872 6915
6873 // Dispatched behavior. 6916 // Dispatched behavior.
6874 #ifdef OBJECT_PRINT 6917 #ifdef OBJECT_PRINT
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
7434 } else { 7477 } else {
7435 value &= ~(1 << bit_position); 7478 value &= ~(1 << bit_position);
7436 } 7479 }
7437 return value; 7480 return value;
7438 } 7481 }
7439 }; 7482 };
7440 7483
7441 } } // namespace v8::internal 7484 } } // namespace v8::internal
7442 7485
7443 #endif // V8_OBJECTS_H_ 7486 #endif // V8_OBJECTS_H_
OLDNEW
« src/bootstrapper.cc ('K') | « src/mips/stub-cache-mips.cc ('k') | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698