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 1402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1413 // caching. | 1413 // caching. |
1414 class JSObject: public JSReceiver { | 1414 class JSObject: public JSReceiver { |
1415 public: | 1415 public: |
1416 enum DeleteMode { | 1416 enum DeleteMode { |
1417 NORMAL_DELETION, | 1417 NORMAL_DELETION, |
1418 STRICT_DELETION, | 1418 STRICT_DELETION, |
1419 FORCE_DELETION | 1419 FORCE_DELETION |
1420 }; | 1420 }; |
1421 | 1421 |
1422 enum ElementsKind { | 1422 enum ElementsKind { |
1423 // The only "fast" kind. | 1423 // The "fast" kind for tagged values. Must be first to make it possible |
| 1424 // to efficiently check maps if they have fast elements. |
1424 FAST_ELEMENTS, | 1425 FAST_ELEMENTS, |
1425 // All the kinds below are "slow". | 1426 // The "slow" kind. |
1426 DICTIONARY_ELEMENTS, | 1427 DICTIONARY_ELEMENTS, |
| 1428 // The "fast" kind for external arrays |
1427 EXTERNAL_BYTE_ELEMENTS, | 1429 EXTERNAL_BYTE_ELEMENTS, |
1428 EXTERNAL_UNSIGNED_BYTE_ELEMENTS, | 1430 EXTERNAL_UNSIGNED_BYTE_ELEMENTS, |
1429 EXTERNAL_SHORT_ELEMENTS, | 1431 EXTERNAL_SHORT_ELEMENTS, |
1430 EXTERNAL_UNSIGNED_SHORT_ELEMENTS, | 1432 EXTERNAL_UNSIGNED_SHORT_ELEMENTS, |
1431 EXTERNAL_INT_ELEMENTS, | 1433 EXTERNAL_INT_ELEMENTS, |
1432 EXTERNAL_UNSIGNED_INT_ELEMENTS, | 1434 EXTERNAL_UNSIGNED_INT_ELEMENTS, |
1433 EXTERNAL_FLOAT_ELEMENTS, | 1435 EXTERNAL_FLOAT_ELEMENTS, |
1434 EXTERNAL_DOUBLE_ELEMENTS, | 1436 EXTERNAL_DOUBLE_ELEMENTS, |
1435 EXTERNAL_PIXEL_ELEMENTS | 1437 EXTERNAL_PIXEL_ELEMENTS, |
| 1438 |
| 1439 // Derived constants from ElementsKind |
| 1440 FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND = EXTERNAL_BYTE_ELEMENTS, |
| 1441 LAST_EXTERNAL_ARRAY_ELEMENTS_KIND = EXTERNAL_PIXEL_ELEMENTS, |
| 1442 FIRST_ELEMENTS_KIND = FAST_ELEMENTS, |
| 1443 LAST_ELEMENTS_KIND = EXTERNAL_PIXEL_ELEMENTS |
1436 }; | 1444 }; |
1437 | 1445 |
| 1446 static const int kElementsKindCount = |
| 1447 LAST_ELEMENTS_KIND - FIRST_ELEMENTS_KIND + 1; |
| 1448 |
1438 // [properties]: Backing storage for properties. | 1449 // [properties]: Backing storage for properties. |
1439 // properties is a FixedArray in the fast case and a Dictionary in the | 1450 // properties is a FixedArray in the fast case and a Dictionary in the |
1440 // slow case. | 1451 // slow case. |
1441 DECL_ACCESSORS(properties, FixedArray) // Get and set fast properties. | 1452 DECL_ACCESSORS(properties, FixedArray) // Get and set fast properties. |
1442 inline void initialize_properties(); | 1453 inline void initialize_properties(); |
1443 inline bool HasFastProperties(); | 1454 inline bool HasFastProperties(); |
1444 inline StringDictionary* property_dictionary(); // Gets slow properties. | 1455 inline StringDictionary* property_dictionary(); // Gets slow properties. |
1445 | 1456 |
1446 // [elements]: The elements (properties with names that are integers). | 1457 // [elements]: The elements (properties with names that are integers). |
1447 // | 1458 // |
(...skipping 2329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3777 set_bit_field(bit_field() | (1 << kHasInstanceCallHandler)); | 3788 set_bit_field(bit_field() | (1 << kHasInstanceCallHandler)); |
3778 } | 3789 } |
3779 | 3790 |
3780 inline bool has_instance_call_handler() { | 3791 inline bool has_instance_call_handler() { |
3781 return ((1 << kHasInstanceCallHandler) & bit_field()) != 0; | 3792 return ((1 << kHasInstanceCallHandler) & bit_field()) != 0; |
3782 } | 3793 } |
3783 | 3794 |
3784 inline void set_is_extensible(bool value); | 3795 inline void set_is_extensible(bool value); |
3785 inline bool is_extensible(); | 3796 inline bool is_extensible(); |
3786 | 3797 |
3787 // Tells whether the instance has fast elements. | 3798 inline void set_elements_kind(JSObject::ElementsKind elements_kind) { |
3788 // Equivalent to instance->GetElementsKind() == FAST_ELEMENTS. | 3799 ASSERT(elements_kind < JSObject::kElementsKindCount); |
3789 inline void set_has_fast_elements(bool value) { | 3800 ASSERT(JSObject::kElementsKindCount <= (1 << kElementsKindBitCount)); |
3790 if (value) { | 3801 set_bit_field2((bit_field2() & ~kElementsKindMask) | |
3791 set_bit_field2(bit_field2() | (1 << kHasFastElements)); | 3802 (elements_kind << kElementsKindShift)); |
3792 } else { | 3803 ASSERT(this->elements_kind() == elements_kind); |
3793 set_bit_field2(bit_field2() & ~(1 << kHasFastElements)); | 3804 } |
3794 } | 3805 |
| 3806 inline JSObject::ElementsKind elements_kind() { |
| 3807 return static_cast<JSObject::ElementsKind>( |
| 3808 (bit_field2() & kElementsKindMask) >> kElementsKindShift); |
3795 } | 3809 } |
3796 | 3810 |
3797 inline bool has_fast_elements() { | 3811 inline bool has_fast_elements() { |
3798 return ((1 << kHasFastElements) & bit_field2()) != 0; | 3812 return elements_kind() == JSObject::FAST_ELEMENTS; |
3799 } | |
3800 | |
3801 // Tells whether an instance has pixel array elements. | |
3802 inline void set_has_external_array_elements(bool value) { | |
3803 if (value) { | |
3804 set_bit_field2(bit_field2() | (1 << kHasExternalArrayElements)); | |
3805 } else { | |
3806 set_bit_field2(bit_field2() & ~(1 << kHasExternalArrayElements)); | |
3807 } | |
3808 } | 3813 } |
3809 | 3814 |
3810 inline bool has_external_array_elements() { | 3815 inline bool has_external_array_elements() { |
3811 return ((1 << kHasExternalArrayElements) & bit_field2()) != 0; | 3816 JSObject::ElementsKind kind(elements_kind()); |
| 3817 return kind >= JSObject::FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND && |
| 3818 kind <= JSObject::LAST_EXTERNAL_ARRAY_ELEMENTS_KIND; |
3812 } | 3819 } |
3813 | 3820 |
3814 // Tells whether the map is attached to SharedFunctionInfo | 3821 // Tells whether the map is attached to SharedFunctionInfo |
3815 // (for inobject slack tracking). | 3822 // (for inobject slack tracking). |
3816 inline void set_attached_to_shared_function_info(bool value); | 3823 inline void set_attached_to_shared_function_info(bool value); |
3817 | 3824 |
3818 inline bool attached_to_shared_function_info(); | 3825 inline bool attached_to_shared_function_info(); |
3819 | 3826 |
3820 // Tells whether the map is shared between objects that may have different | 3827 // Tells whether the map is shared between objects that may have different |
3821 // behavior. If true, the map should never be modified, instead a clone | 3828 // behavior. If true, the map should never be modified, instead a clone |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4022 static const int kIsHiddenPrototype = 2; | 4029 static const int kIsHiddenPrototype = 2; |
4023 static const int kHasNamedInterceptor = 3; | 4030 static const int kHasNamedInterceptor = 3; |
4024 static const int kHasIndexedInterceptor = 4; | 4031 static const int kHasIndexedInterceptor = 4; |
4025 static const int kIsUndetectable = 5; | 4032 static const int kIsUndetectable = 5; |
4026 static const int kHasInstanceCallHandler = 6; | 4033 static const int kHasInstanceCallHandler = 6; |
4027 static const int kIsAccessCheckNeeded = 7; | 4034 static const int kIsAccessCheckNeeded = 7; |
4028 | 4035 |
4029 // Bit positions for bit field 2 | 4036 // Bit positions for bit field 2 |
4030 static const int kIsExtensible = 0; | 4037 static const int kIsExtensible = 0; |
4031 static const int kFunctionWithPrototype = 1; | 4038 static const int kFunctionWithPrototype = 1; |
4032 static const int kHasFastElements = 2; | 4039 static const int kStringWrapperSafeForDefaultValueOf = 2; |
4033 static const int kStringWrapperSafeForDefaultValueOf = 3; | 4040 static const int kAttachedToSharedFunctionInfo = 3; |
4034 static const int kAttachedToSharedFunctionInfo = 4; | 4041 // No bits can be used after kElementsKindFirstBit, they are all reserved for |
4035 static const int kHasExternalArrayElements = 5; | 4042 // storing ElementKind. for anything other than storing the ElementKind. |
| 4043 static const int kElementsKindShift = 4; |
| 4044 static const int kElementsKindBitCount = 4; |
| 4045 |
| 4046 // Derived values from bit field 2 |
| 4047 static const int kElementsKindMask = (-1 << kElementsKindShift) & |
| 4048 ((1 << (kElementsKindShift + kElementsKindBitCount)) - 1); |
| 4049 static const int8_t kMaximumBitField2FastElementValue = static_cast<int8_t>( |
| 4050 (JSObject::FAST_ELEMENTS + 1) << Map::kElementsKindShift) - 1; |
4036 | 4051 |
4037 // Bit positions for bit field 3 | 4052 // Bit positions for bit field 3 |
4038 static const int kIsShared = 1; | 4053 static const int kIsShared = 0; |
4039 | 4054 |
4040 // Layout of the default cache. It holds alternating name and code objects. | 4055 // Layout of the default cache. It holds alternating name and code objects. |
4041 static const int kCodeCacheEntrySize = 2; | 4056 static const int kCodeCacheEntrySize = 2; |
4042 static const int kCodeCacheEntryNameOffset = 0; | 4057 static const int kCodeCacheEntryNameOffset = 0; |
4043 static const int kCodeCacheEntryCodeOffset = 1; | 4058 static const int kCodeCacheEntryCodeOffset = 1; |
4044 | 4059 |
4045 typedef FixedBodyDescriptor<kPointerFieldsBeginOffset, | 4060 typedef FixedBodyDescriptor<kPointerFieldsBeginOffset, |
4046 kPointerFieldsEndOffset, | 4061 kPointerFieldsEndOffset, |
4047 kSize> BodyDescriptor; | 4062 kSize> BodyDescriptor; |
4048 | 4063 |
(...skipping 2844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6893 } else { | 6908 } else { |
6894 value &= ~(1 << bit_position); | 6909 value &= ~(1 << bit_position); |
6895 } | 6910 } |
6896 return value; | 6911 return value; |
6897 } | 6912 } |
6898 }; | 6913 }; |
6899 | 6914 |
6900 } } // namespace v8::internal | 6915 } } // namespace v8::internal |
6901 | 6916 |
6902 #endif // V8_OBJECTS_H_ | 6917 #endif // V8_OBJECTS_H_ |
OLD | NEW |