OLD | NEW |
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 1636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1647 // Do we want to keep the elements in fast case when increasing the | 1647 // Do we want to keep the elements in fast case when increasing the |
1648 // capacity? | 1648 // capacity? |
1649 bool ShouldConvertToSlowElements(int new_capacity); | 1649 bool ShouldConvertToSlowElements(int new_capacity); |
1650 // Returns true if the backing storage for the slow-case elements of | 1650 // Returns true if the backing storage for the slow-case elements of |
1651 // this object takes up nearly as much space as a fast-case backing | 1651 // this object takes up nearly as much space as a fast-case backing |
1652 // storage would. In that case the JSObject should have fast | 1652 // storage would. In that case the JSObject should have fast |
1653 // elements. | 1653 // elements. |
1654 bool ShouldConvertToFastElements(); | 1654 bool ShouldConvertToFastElements(); |
1655 // Returns true if the elements of JSObject contains only values that can be | 1655 // Returns true if the elements of JSObject contains only values that can be |
1656 // represented in a FixedDoubleArray. | 1656 // represented in a FixedDoubleArray. |
1657 bool ShouldConvertToFastDoubleElements(); | 1657 bool CanConvertToFastDoubleElements(); |
1658 | 1658 |
1659 // Tells whether the index'th element is present. | 1659 // Tells whether the index'th element is present. |
1660 inline bool HasElement(uint32_t index); | 1660 inline bool HasElement(uint32_t index); |
1661 bool HasElementWithReceiver(JSReceiver* receiver, uint32_t index); | 1661 bool HasElementWithReceiver(JSReceiver* receiver, uint32_t index); |
1662 | 1662 |
1663 // Computes the new capacity when expanding the elements of a JSObject. | 1663 // Computes the new capacity when expanding the elements of a JSObject. |
1664 static int NewElementsCapacity(int old_capacity) { | 1664 static int NewElementsCapacity(int old_capacity) { |
1665 // (old_capacity + 50%) + 16 | 1665 // (old_capacity + 50%) + 16 |
1666 return old_capacity + (old_capacity >> 1) + 16; | 1666 return old_capacity + (old_capacity >> 1) + 16; |
1667 } | 1667 } |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1941 | 1941 |
1942 // Maximal number of fast properties for the JSObject. Used to | 1942 // Maximal number of fast properties for the JSObject. Used to |
1943 // restrict the number of map transitions to avoid an explosion in | 1943 // restrict the number of map transitions to avoid an explosion in |
1944 // the number of maps for objects used as dictionaries. | 1944 // the number of maps for objects used as dictionaries. |
1945 inline int MaxFastProperties(); | 1945 inline int MaxFastProperties(); |
1946 | 1946 |
1947 // Maximal number of elements (numbered 0 .. kMaxElementCount - 1). | 1947 // Maximal number of elements (numbered 0 .. kMaxElementCount - 1). |
1948 // Also maximal value of JSArray's length property. | 1948 // Also maximal value of JSArray's length property. |
1949 static const uint32_t kMaxElementCount = 0xffffffffu; | 1949 static const uint32_t kMaxElementCount = 0xffffffffu; |
1950 | 1950 |
| 1951 // Constants for heuristics controlling conversion of fast elements |
| 1952 // to slow elements. |
| 1953 |
| 1954 // Maximal gap that can be introduced by adding an element beyond |
| 1955 // the current elements length. |
1951 static const uint32_t kMaxGap = 1024; | 1956 static const uint32_t kMaxGap = 1024; |
1952 static const int kMaxFastElementsLength = 5000; | 1957 |
| 1958 // Maximal length of fast elements array that won't be checked for |
| 1959 // being dense enough on expansion. |
| 1960 static const int kMaxUncheckedFastElementsLength = 5000; |
| 1961 |
| 1962 // Same as above but for old arrays. This limit is more strict. We |
| 1963 // don't want to be wasteful with long lived objects. |
| 1964 static const int kMaxUncheckedOldFastElementsLength = 500; |
| 1965 |
1953 static const int kInitialMaxFastElementArray = 100000; | 1966 static const int kInitialMaxFastElementArray = 100000; |
1954 static const int kMaxFastProperties = 12; | 1967 static const int kMaxFastProperties = 12; |
1955 static const int kMaxInstanceSize = 255 * kPointerSize; | 1968 static const int kMaxInstanceSize = 255 * kPointerSize; |
1956 // When extending the backing storage for property values, we increase | 1969 // When extending the backing storage for property values, we increase |
1957 // its size by more than the 1 entry necessary, so sequentially adding fields | 1970 // its size by more than the 1 entry necessary, so sequentially adding fields |
1958 // to the same object requires fewer allocations and copies. | 1971 // to the same object requires fewer allocations and copies. |
1959 static const int kFieldsAdded = 3; | 1972 static const int kFieldsAdded = 3; |
1960 | 1973 |
1961 // Layout description. | 1974 // Layout description. |
1962 static const int kPropertiesOffset = HeapObject::kHeaderSize; | 1975 static const int kPropertiesOffset = HeapObject::kHeaderSize; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2008 bool ReferencesObjectFromElements(FixedArray* elements, | 2021 bool ReferencesObjectFromElements(FixedArray* elements, |
2009 ElementsKind kind, | 2022 ElementsKind kind, |
2010 Object* object); | 2023 Object* object); |
2011 bool HasElementInElements(FixedArray* elements, | 2024 bool HasElementInElements(FixedArray* elements, |
2012 ElementsKind kind, | 2025 ElementsKind kind, |
2013 uint32_t index); | 2026 uint32_t index); |
2014 | 2027 |
2015 // Returns true if most of the elements backing storage is used. | 2028 // Returns true if most of the elements backing storage is used. |
2016 bool HasDenseElements(); | 2029 bool HasDenseElements(); |
2017 | 2030 |
| 2031 // Gets the current elements capacity and the number of used elements. |
| 2032 void GetElementsCapacityAndUsage(int* capacity, int* used); |
| 2033 |
2018 bool CanSetCallback(String* name); | 2034 bool CanSetCallback(String* name); |
2019 MUST_USE_RESULT MaybeObject* SetElementCallback( | 2035 MUST_USE_RESULT MaybeObject* SetElementCallback( |
2020 uint32_t index, | 2036 uint32_t index, |
2021 Object* structure, | 2037 Object* structure, |
2022 PropertyAttributes attributes); | 2038 PropertyAttributes attributes); |
2023 MUST_USE_RESULT MaybeObject* SetPropertyCallback( | 2039 MUST_USE_RESULT MaybeObject* SetPropertyCallback( |
2024 String* name, | 2040 String* name, |
2025 Object* structure, | 2041 Object* structure, |
2026 PropertyAttributes attributes); | 2042 PropertyAttributes attributes); |
2027 MUST_USE_RESULT MaybeObject* DefineGetterSetter( | 2043 MUST_USE_RESULT MaybeObject* DefineGetterSetter( |
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2484 void ElementsRemoved(int n) { | 2500 void ElementsRemoved(int n) { |
2485 SetNumberOfElements(NumberOfElements() - n); | 2501 SetNumberOfElements(NumberOfElements() - n); |
2486 SetNumberOfDeletedElements(NumberOfDeletedElements() + n); | 2502 SetNumberOfDeletedElements(NumberOfDeletedElements() + n); |
2487 } | 2503 } |
2488 | 2504 |
2489 // Returns a new HashTable object. Might return Failure. | 2505 // Returns a new HashTable object. Might return Failure. |
2490 MUST_USE_RESULT static MaybeObject* Allocate( | 2506 MUST_USE_RESULT static MaybeObject* Allocate( |
2491 int at_least_space_for, | 2507 int at_least_space_for, |
2492 PretenureFlag pretenure = NOT_TENURED); | 2508 PretenureFlag pretenure = NOT_TENURED); |
2493 | 2509 |
| 2510 // Computes the required capacity for a table holding the given |
| 2511 // number of elements. May be more than HashTable::kMaxCapacity. |
| 2512 static int ComputeCapacity(int at_least_space_for); |
| 2513 |
2494 // Returns the key at entry. | 2514 // Returns the key at entry. |
2495 Object* KeyAt(int entry) { return get(EntryToIndex(entry)); } | 2515 Object* KeyAt(int entry) { return get(EntryToIndex(entry)); } |
2496 | 2516 |
2497 // Tells whether k is a real key. Null and undefined are not allowed | 2517 // Tells whether k is a real key. Null and undefined are not allowed |
2498 // as keys and can be used to indicate missing or deleted elements. | 2518 // as keys and can be used to indicate missing or deleted elements. |
2499 bool IsKey(Object* k) { | 2519 bool IsKey(Object* k) { |
2500 return !k->IsNull() && !k->IsUndefined(); | 2520 return !k->IsNull() && !k->IsUndefined(); |
2501 } | 2521 } |
2502 | 2522 |
2503 // Garbage collection support. | 2523 // Garbage collection support. |
(...skipping 4679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7183 } else { | 7203 } else { |
7184 value &= ~(1 << bit_position); | 7204 value &= ~(1 << bit_position); |
7185 } | 7205 } |
7186 return value; | 7206 return value; |
7187 } | 7207 } |
7188 }; | 7208 }; |
7189 | 7209 |
7190 } } // namespace v8::internal | 7210 } } // namespace v8::internal |
7191 | 7211 |
7192 #endif // V8_OBJECTS_H_ | 7212 #endif // V8_OBJECTS_H_ |
OLD | NEW |