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

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: deactivate by default 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 ABSENT = 16 // Used in runtime to indicate a property is absent. 129 ABSENT = 16 // Used in runtime to indicate a property is absent.
130 // ABSENT can never be stored in or returned from a descriptor's attributes 130 // ABSENT can never be stored in or returned from a descriptor's attributes
131 // bitfield. It is only used as a return value meaning the attributes of 131 // bitfield. It is only used as a return value meaning the attributes of
132 // a non-existent property. 132 // a non-existent property.
133 }; 133 };
134 134
135 namespace v8 { 135 namespace v8 {
136 namespace internal { 136 namespace internal {
137 137
138 enum ElementsKind { 138 enum ElementsKind {
139 // The "fast" kind for elements that only contain SMI values.
140 FAST_SMI_ONLY_ELEMENTS,
141
139 // The "fast" kind for tagged values. Must be first to make it possible 142 // The "fast" kind for tagged values. Must be first to make it possible
140 // to efficiently check maps if they have fast elements. 143 // to efficiently check maps if they have fast elements.
Yang 2011/09/19 14:00:15 Outdated comment. (Any consequences since the assu
danno 2011/09/21 14:32:04 Done.
141 FAST_ELEMENTS, 144 FAST_ELEMENTS,
142 145
143 // The "fast" kind for unwrapped, non-tagged double values. 146 // The "fast" kind for unwrapped, non-tagged double values.
144 FAST_DOUBLE_ELEMENTS, 147 FAST_DOUBLE_ELEMENTS,
145 148
146 // The "slow" kind. 149 // The "slow" kind.
147 DICTIONARY_ELEMENTS, 150 DICTIONARY_ELEMENTS,
148 NON_STRICT_ARGUMENTS_ELEMENTS, 151 NON_STRICT_ARGUMENTS_ELEMENTS,
149 // The "fast" kind for external arrays 152 // The "fast" kind for external arrays
150 EXTERNAL_BYTE_ELEMENTS, 153 EXTERNAL_BYTE_ELEMENTS,
151 EXTERNAL_UNSIGNED_BYTE_ELEMENTS, 154 EXTERNAL_UNSIGNED_BYTE_ELEMENTS,
152 EXTERNAL_SHORT_ELEMENTS, 155 EXTERNAL_SHORT_ELEMENTS,
153 EXTERNAL_UNSIGNED_SHORT_ELEMENTS, 156 EXTERNAL_UNSIGNED_SHORT_ELEMENTS,
154 EXTERNAL_INT_ELEMENTS, 157 EXTERNAL_INT_ELEMENTS,
155 EXTERNAL_UNSIGNED_INT_ELEMENTS, 158 EXTERNAL_UNSIGNED_INT_ELEMENTS,
156 EXTERNAL_FLOAT_ELEMENTS, 159 EXTERNAL_FLOAT_ELEMENTS,
157 EXTERNAL_DOUBLE_ELEMENTS, 160 EXTERNAL_DOUBLE_ELEMENTS,
158 EXTERNAL_PIXEL_ELEMENTS, 161 EXTERNAL_PIXEL_ELEMENTS,
159 162
160 // Derived constants from ElementsKind 163 // Derived constants from ElementsKind
161 FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND = EXTERNAL_BYTE_ELEMENTS, 164 FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND = EXTERNAL_BYTE_ELEMENTS,
162 LAST_EXTERNAL_ARRAY_ELEMENTS_KIND = EXTERNAL_PIXEL_ELEMENTS, 165 LAST_EXTERNAL_ARRAY_ELEMENTS_KIND = EXTERNAL_PIXEL_ELEMENTS,
163 FIRST_ELEMENTS_KIND = FAST_ELEMENTS, 166 FIRST_ELEMENTS_KIND = FAST_SMI_ONLY_ELEMENTS,
164 LAST_ELEMENTS_KIND = EXTERNAL_PIXEL_ELEMENTS 167 LAST_ELEMENTS_KIND = EXTERNAL_PIXEL_ELEMENTS
165 }; 168 };
166 169
167 static const int kElementsKindCount = 170 static const int kElementsKindCount =
168 LAST_ELEMENTS_KIND - FIRST_ELEMENTS_KIND + 1; 171 LAST_ELEMENTS_KIND - FIRST_ELEMENTS_KIND + 1;
169 172
170 // PropertyDetails captures type and attributes for a property. 173 // PropertyDetails captures type and attributes for a property.
171 // They are used both in property dictionaries and instance descriptors. 174 // They are used both in property dictionaries and instance descriptors.
172 class PropertyDetails BASE_EMBEDDED { 175 class PropertyDetails BASE_EMBEDDED {
173 public: 176 public:
(...skipping 1344 matching lines...) Expand 10 before | Expand all | Expand 10 after
1518 // EnsureWritableFastElements in this case. 1521 // EnsureWritableFastElements in this case.
1519 // 1522 //
1520 // In the slow mode the elements is either a NumberDictionary, an 1523 // In the slow mode the elements is either a NumberDictionary, an
1521 // ExternalArray, or a FixedArray parameter map for a (non-strict) 1524 // ExternalArray, or a FixedArray parameter map for a (non-strict)
1522 // arguments object. 1525 // arguments object.
1523 DECL_ACCESSORS(elements, FixedArrayBase) 1526 DECL_ACCESSORS(elements, FixedArrayBase)
1524 inline void initialize_elements(); 1527 inline void initialize_elements();
1525 MUST_USE_RESULT inline MaybeObject* ResetElements(); 1528 MUST_USE_RESULT inline MaybeObject* ResetElements();
1526 inline ElementsKind GetElementsKind(); 1529 inline ElementsKind GetElementsKind();
1527 inline ElementsAccessor* GetElementsAccessor(); 1530 inline ElementsAccessor* GetElementsAccessor();
1531 inline bool HasFastSmiOnlyElements();
Rico 2011/09/16 09:40:10 Do we want to include something like HasFastTypeEl
danno 2011/09/21 14:32:04 On 2011/09/16 09:40:10, Rico wrote: > Do we want t
1528 inline bool HasFastElements(); 1532 inline bool HasFastElements();
1529 inline bool HasFastDoubleElements(); 1533 inline bool HasFastDoubleElements();
1534 inline bool HasNonStrictArgumentsElements();
1530 inline bool HasDictionaryElements(); 1535 inline bool HasDictionaryElements();
1531 inline bool HasExternalPixelElements(); 1536 inline bool HasExternalPixelElements();
1532 inline bool HasExternalArrayElements(); 1537 inline bool HasExternalArrayElements();
1533 inline bool HasExternalByteElements(); 1538 inline bool HasExternalByteElements();
1534 inline bool HasExternalUnsignedByteElements(); 1539 inline bool HasExternalUnsignedByteElements();
1535 inline bool HasExternalShortElements(); 1540 inline bool HasExternalShortElements();
1536 inline bool HasExternalUnsignedShortElements(); 1541 inline bool HasExternalUnsignedShortElements();
1537 inline bool HasExternalIntElements(); 1542 inline bool HasExternalIntElements();
1538 inline bool HasExternalUnsignedIntElements(); 1543 inline bool HasExternalUnsignedIntElements();
1539 inline bool HasExternalFloatElements(); 1544 inline bool HasExternalFloatElements();
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1691 // be returned in case no hidden properties object is present and creation was 1696 // be returned in case no hidden properties object is present and creation was
1692 // omitted. 1697 // omitted.
1693 MUST_USE_RESULT MaybeObject* GetIdentityHash(HiddenPropertiesFlag flag); 1698 MUST_USE_RESULT MaybeObject* GetIdentityHash(HiddenPropertiesFlag flag);
1694 1699
1695 MUST_USE_RESULT MaybeObject* DeleteProperty(String* name, DeleteMode mode); 1700 MUST_USE_RESULT MaybeObject* DeleteProperty(String* name, DeleteMode mode);
1696 MUST_USE_RESULT MaybeObject* DeleteElement(uint32_t index, DeleteMode mode); 1701 MUST_USE_RESULT MaybeObject* DeleteElement(uint32_t index, DeleteMode mode);
1697 1702
1698 // Tests for the fast common case for property enumeration. 1703 // Tests for the fast common case for property enumeration.
1699 bool IsSimpleEnum(); 1704 bool IsSimpleEnum();
1700 1705
1706 // Makes sure the elements can contain non-smi Object.
1707 inline MaybeObject* EnsureCanContainNonSmiElements();
1708
1709 // Make sure that elements can contain the specified elements.
Jakob Kummerow 2011/09/16 16:30:34 The comments for both these methods deserve better
danno 2011/09/21 14:32:04 Done.
1710 inline MaybeObject* EnsureCanContainElements(Object** elements,
1711 uint32_t count);
1712 inline MaybeObject* EnsureCanContainElements(FixedArray* elements);
1713 MaybeObject* EnsureCanContainElements(Arguments* arguments,
1714 uint32_t first_arg,
1715 uint32_t arg_count);
1716
1701 // Do we want to keep the elements in fast case when increasing the 1717 // Do we want to keep the elements in fast case when increasing the
1702 // capacity? 1718 // capacity?
1703 bool ShouldConvertToSlowElements(int new_capacity); 1719 bool ShouldConvertToSlowElements(int new_capacity);
1704 // Returns true if the backing storage for the slow-case elements of 1720 // Returns true if the backing storage for the slow-case elements of
1705 // this object takes up nearly as much space as a fast-case backing 1721 // this object takes up nearly as much space as a fast-case backing
1706 // storage would. In that case the JSObject should have fast 1722 // storage would. In that case the JSObject should have fast
1707 // elements. 1723 // elements.
1708 bool ShouldConvertToFastElements(); 1724 bool ShouldConvertToFastElements();
1709 // Returns true if the elements of JSObject contains only values that can be 1725 // Returns true if the elements of JSObject contains only values that can be
1710 // represented in a FixedDoubleArray. 1726 // represented in a FixedDoubleArray.
(...skipping 29 matching lines...) Expand all
1740 1756
1741 LocalElementType HasLocalElement(uint32_t index); 1757 LocalElementType HasLocalElement(uint32_t index);
1742 1758
1743 bool HasElementWithInterceptor(JSReceiver* receiver, uint32_t index); 1759 bool HasElementWithInterceptor(JSReceiver* receiver, uint32_t index);
1744 bool HasElementPostInterceptor(JSReceiver* receiver, uint32_t index); 1760 bool HasElementPostInterceptor(JSReceiver* receiver, uint32_t index);
1745 1761
1746 MUST_USE_RESULT MaybeObject* SetFastElement(uint32_t index, 1762 MUST_USE_RESULT MaybeObject* SetFastElement(uint32_t index,
1747 Object* value, 1763 Object* value,
1748 StrictModeFlag strict_mode, 1764 StrictModeFlag strict_mode,
1749 bool check_prototype); 1765 bool check_prototype);
1766
1750 MUST_USE_RESULT MaybeObject* SetDictionaryElement(uint32_t index, 1767 MUST_USE_RESULT MaybeObject* SetDictionaryElement(uint32_t index,
1751 Object* value, 1768 Object* value,
1752 StrictModeFlag strict_mode, 1769 StrictModeFlag strict_mode,
1753 bool check_prototype); 1770 bool check_prototype);
1754 1771
1755 MUST_USE_RESULT MaybeObject* SetFastDoubleElement( 1772 MUST_USE_RESULT MaybeObject* SetFastDoubleElement(
1756 uint32_t index, 1773 uint32_t index,
1757 Object* value, 1774 Object* value,
1758 StrictModeFlag strict_mode, 1775 StrictModeFlag strict_mode,
1759 bool check_prototype = true); 1776 bool check_prototype = true);
1760 1777
1761 // Set the index'th array element. 1778 // Set the index'th array element.
1762 // A Failure object is returned if GC is needed. 1779 // A Failure object is returned if GC is needed.
1763 MUST_USE_RESULT MaybeObject* SetElement(uint32_t index, 1780 MUST_USE_RESULT MaybeObject* SetElement(uint32_t index,
1764 Object* value, 1781 Object* value,
1765 StrictModeFlag strict_mode, 1782 StrictModeFlag strict_mode,
1766 bool check_prototype); 1783 bool check_prototype);
1767 1784
1768 // Returns the index'th element. 1785 // Returns the index'th element.
1769 // The undefined object if index is out of bounds. 1786 // The undefined object if index is out of bounds.
1770 MaybeObject* GetElementWithInterceptor(Object* receiver, uint32_t index); 1787 MaybeObject* GetElementWithInterceptor(Object* receiver, uint32_t index);
1771 1788
1789 enum SetFastElementsCapacityMode {
1790 kAllowSmiOnlyElements,
1791 kDontAllowSmiOnlyElements
1792 };
1793
1772 // Replace the elements' backing store with fast elements of the given 1794 // Replace the elements' backing store with fast elements of the given
1773 // capacity. Update the length for JSArrays. Returns the new backing 1795 // capacity. Update the length for JSArrays. Returns the new backing
1774 // store. 1796 // store.
1775 MUST_USE_RESULT MaybeObject* SetFastElementsCapacityAndLength(int capacity, 1797 MUST_USE_RESULT MaybeObject* SetFastElementsCapacityAndLength(
1776 int length); 1798 int capacity,
1799 int length,
1800 SetFastElementsCapacityMode set_capacity_mode);
1777 MUST_USE_RESULT MaybeObject* SetFastDoubleElementsCapacityAndLength( 1801 MUST_USE_RESULT MaybeObject* SetFastDoubleElementsCapacityAndLength(
1778 int capacity, 1802 int capacity,
1779 int length); 1803 int length);
1780 MUST_USE_RESULT MaybeObject* SetSlowElements(Object* length); 1804 MUST_USE_RESULT MaybeObject* SetSlowElements(Object* length);
1781 1805
1782 // Lookup interceptors are used for handling properties controlled by host 1806 // Lookup interceptors are used for handling properties controlled by host
1783 // objects. 1807 // objects.
1784 inline bool HasNamedInterceptor(); 1808 inline bool HasNamedInterceptor();
1785 inline bool HasIndexedInterceptor(); 1809 inline bool HasIndexedInterceptor();
1786 1810
(...skipping 2249 matching lines...) Expand 10 before | Expand all | Expand 10 after
4036 set_bit_field2((bit_field2() & ~kElementsKindMask) | 4060 set_bit_field2((bit_field2() & ~kElementsKindMask) |
4037 (elements_kind << kElementsKindShift)); 4061 (elements_kind << kElementsKindShift));
4038 ASSERT(this->elements_kind() == elements_kind); 4062 ASSERT(this->elements_kind() == elements_kind);
4039 } 4063 }
4040 4064
4041 inline ElementsKind elements_kind() { 4065 inline ElementsKind elements_kind() {
4042 return static_cast<ElementsKind>( 4066 return static_cast<ElementsKind>(
4043 (bit_field2() & kElementsKindMask) >> kElementsKindShift); 4067 (bit_field2() & kElementsKindMask) >> kElementsKindShift);
4044 } 4068 }
4045 4069
4070 // Tells whether the instance has fast elements that are only Smis.
4071 inline bool has_fast_smi_only_elements() {
4072 return elements_kind() == FAST_SMI_ONLY_ELEMENTS;
4073 }
4074
4046 // Tells whether the instance has fast elements. 4075 // Tells whether the instance has fast elements.
4047 // Equivalent to instance->GetElementsKind() == FAST_ELEMENTS.
4048 inline bool has_fast_elements() { 4076 inline bool has_fast_elements() {
4049 return elements_kind() == FAST_ELEMENTS; 4077 return elements_kind() == FAST_ELEMENTS;
4050 } 4078 }
4051 4079
4052 inline bool has_fast_double_elements() { 4080 inline bool has_fast_double_elements() {
4053 return elements_kind() == FAST_DOUBLE_ELEMENTS; 4081 return elements_kind() == FAST_DOUBLE_ELEMENTS;
4054 } 4082 }
4055 4083
4084 inline bool has_non_strict_arguments_elements() {
4085 return elements_kind() == NON_STRICT_ARGUMENTS_ELEMENTS;
4086 }
4087
4056 inline bool has_external_array_elements() { 4088 inline bool has_external_array_elements() {
4057 ElementsKind kind(elements_kind()); 4089 ElementsKind kind(elements_kind());
4058 return kind >= FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND && 4090 return kind >= FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND &&
4059 kind <= LAST_EXTERNAL_ARRAY_ELEMENTS_KIND; 4091 kind <= LAST_EXTERNAL_ARRAY_ELEMENTS_KIND;
4060 } 4092 }
4061 4093
4062 inline bool has_dictionary_elements() { 4094 inline bool has_dictionary_elements() {
4063 return elements_kind() == DICTIONARY_ELEMENTS; 4095 return elements_kind() == DICTIONARY_ELEMENTS;
4064 } 4096 }
4065 4097
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
4296 static const int kIsUndetectable = 5; 4328 static const int kIsUndetectable = 5;
4297 static const int kHasInstanceCallHandler = 6; 4329 static const int kHasInstanceCallHandler = 6;
4298 static const int kIsAccessCheckNeeded = 7; 4330 static const int kIsAccessCheckNeeded = 7;
4299 4331
4300 // Bit positions for bit field 2 4332 // Bit positions for bit field 2
4301 static const int kIsExtensible = 0; 4333 static const int kIsExtensible = 0;
4302 static const int kFunctionWithPrototype = 1; 4334 static const int kFunctionWithPrototype = 1;
4303 static const int kStringWrapperSafeForDefaultValueOf = 2; 4335 static const int kStringWrapperSafeForDefaultValueOf = 2;
4304 static const int kAttachedToSharedFunctionInfo = 3; 4336 static const int kAttachedToSharedFunctionInfo = 3;
4305 // No bits can be used after kElementsKindFirstBit, they are all reserved for 4337 // No bits can be used after kElementsKindFirstBit, they are all reserved for
4306 // storing ElementKind. for anything other than storing the ElementKind. 4338 // storing ElementKind. for anything other than storing the ElementKind.
Jakob Kummerow 2011/09/16 16:30:34 nit: messed up comment (just remove second sentenc
danno 2011/09/21 14:32:04 Done.
4307 static const int kElementsKindShift = 4; 4339 static const int kElementsKindShift = 4;
4308 static const int kElementsKindBitCount = 4; 4340 static const int kElementsKindBitCount = 4;
4309 4341
4310 // Derived values from bit field 2 4342 // Derived values from bit field 2
4311 static const int kElementsKindMask = (-1 << kElementsKindShift) & 4343 static const int kElementsKindMask = (-1 << kElementsKindShift) &
4312 ((1 << (kElementsKindShift + kElementsKindBitCount)) - 1); 4344 ((1 << (kElementsKindShift + kElementsKindBitCount)) - 1);
4313 static const int8_t kMaximumBitField2FastElementValue = static_cast<int8_t>( 4345 static const int8_t kMaximumBitField2FastElementValue = static_cast<int8_t>(
4314 (FAST_ELEMENTS + 1) << Map::kElementsKindShift) - 1; 4346 (FAST_ELEMENTS + 1) << Map::kElementsKindShift) - 1;
4347 static const int8_t kMaximumBitField2FastSmiOnlyElementValue =
4348 static_cast<int8_t>((FAST_SMI_ONLY_ELEMENTS + 1) <<
4349 Map::kElementsKindShift) - 1;
4315 4350
4316 // Bit positions for bit field 3 4351 // Bit positions for bit field 3
4317 static const int kIsShared = 0; 4352 static const int kIsShared = 0;
4318 4353
4319 // Layout of the default cache. It holds alternating name and code objects. 4354 // Layout of the default cache. It holds alternating name and code objects.
4320 static const int kCodeCacheEntrySize = 2; 4355 static const int kCodeCacheEntrySize = 2;
4321 static const int kCodeCacheEntryNameOffset = 0; 4356 static const int kCodeCacheEntryNameOffset = 0;
4322 static const int kCodeCacheEntryCodeOffset = 1; 4357 static const int kCodeCacheEntryCodeOffset = 1;
4323 4358
4324 typedef FixedBodyDescriptor<kPointerFieldsBeginOffset, 4359 typedef FixedBodyDescriptor<kPointerFieldsBeginOffset,
(...skipping 2540 matching lines...) Expand 10 before | Expand all | Expand 10 after
6865 6900
6866 MUST_USE_RESULT MaybeObject* JSArrayUpdateLengthFromIndex(uint32_t index, 6901 MUST_USE_RESULT MaybeObject* JSArrayUpdateLengthFromIndex(uint32_t index,
6867 Object* value); 6902 Object* value);
6868 6903
6869 // Initialize the array with the given capacity. The function may 6904 // Initialize the array with the given capacity. The function may
6870 // fail due to out-of-memory situations, but only if the requested 6905 // fail due to out-of-memory situations, but only if the requested
6871 // capacity is non-zero. 6906 // capacity is non-zero.
6872 MUST_USE_RESULT MaybeObject* Initialize(int capacity); 6907 MUST_USE_RESULT MaybeObject* Initialize(int capacity);
6873 6908
6874 // Set the content of the array to the content of storage. 6909 // Set the content of the array to the content of storage.
6875 inline void SetContent(FixedArray* storage); 6910 inline MaybeObject* SetContent(FixedArray* storage);
6876 6911
6877 // Casting. 6912 // Casting.
6878 static inline JSArray* cast(Object* obj); 6913 static inline JSArray* cast(Object* obj);
6879 6914
6880 // Uses handles. Ensures that the fixed array backing the JSArray has at 6915 // Uses handles. Ensures that the fixed array backing the JSArray has at
6881 // least the stated size. 6916 // least the stated size.
6882 inline void EnsureSize(int minimum_size_of_backing_fixed_array); 6917 inline void EnsureSize(int minimum_size_of_backing_fixed_array);
6883 6918
6884 // Dispatched behavior. 6919 // Dispatched behavior.
6885 #ifdef OBJECT_PRINT 6920 #ifdef OBJECT_PRINT
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
7445 } else { 7480 } else {
7446 value &= ~(1 << bit_position); 7481 value &= ~(1 << bit_position);
7447 } 7482 }
7448 return value; 7483 return value;
7449 } 7484 }
7450 }; 7485 };
7451 7486
7452 } } // namespace v8::internal 7487 } } // namespace v8::internal
7453 7488
7454 #endif // V8_OBJECTS_H_ 7489 #endif // V8_OBJECTS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698