| 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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 DONT_DELETE = v8::DontDelete, | 128 DONT_DELETE = v8::DontDelete, |
| 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 { |
| 139 // The "fast" kind for tagged values. Must be first to make it possible |
| 140 // to efficiently check maps if they have fast elements. |
| 141 FAST_ELEMENTS, |
| 142 |
| 143 // The "fast" kind for unwrapped, non-tagged double values. |
| 144 FAST_DOUBLE_ELEMENTS, |
| 145 |
| 146 // The "slow" kind. |
| 147 DICTIONARY_ELEMENTS, |
| 148 NON_STRICT_ARGUMENTS_ELEMENTS, |
| 149 // The "fast" kind for external arrays |
| 150 EXTERNAL_BYTE_ELEMENTS, |
| 151 EXTERNAL_UNSIGNED_BYTE_ELEMENTS, |
| 152 EXTERNAL_SHORT_ELEMENTS, |
| 153 EXTERNAL_UNSIGNED_SHORT_ELEMENTS, |
| 154 EXTERNAL_INT_ELEMENTS, |
| 155 EXTERNAL_UNSIGNED_INT_ELEMENTS, |
| 156 EXTERNAL_FLOAT_ELEMENTS, |
| 157 EXTERNAL_DOUBLE_ELEMENTS, |
| 158 EXTERNAL_PIXEL_ELEMENTS, |
| 159 |
| 160 // Derived constants from ElementsKind |
| 161 FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND = EXTERNAL_BYTE_ELEMENTS, |
| 162 LAST_EXTERNAL_ARRAY_ELEMENTS_KIND = EXTERNAL_PIXEL_ELEMENTS, |
| 163 FIRST_ELEMENTS_KIND = FAST_ELEMENTS, |
| 164 LAST_ELEMENTS_KIND = EXTERNAL_PIXEL_ELEMENTS |
| 165 }; |
| 166 |
| 167 static const int kElementsKindCount = |
| 168 LAST_ELEMENTS_KIND - FIRST_ELEMENTS_KIND + 1; |
| 138 | 169 |
| 139 // PropertyDetails captures type and attributes for a property. | 170 // PropertyDetails captures type and attributes for a property. |
| 140 // They are used both in property dictionaries and instance descriptors. | 171 // They are used both in property dictionaries and instance descriptors. |
| 141 class PropertyDetails BASE_EMBEDDED { | 172 class PropertyDetails BASE_EMBEDDED { |
| 142 public: | 173 public: |
| 143 PropertyDetails(PropertyAttributes attributes, | 174 PropertyDetails(PropertyAttributes attributes, |
| 144 PropertyType type, | 175 PropertyType type, |
| 145 int index = 0) { | 176 int index = 0) { |
| 146 ASSERT(type != EXTERNAL_ARRAY_TRANSITION); | 177 ASSERT(type != EXTERNAL_ARRAY_TRANSITION); |
| 147 ASSERT(TypeField::is_valid(type)); | 178 ASSERT(TypeField::is_valid(type)); |
| (...skipping 1308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1456 | 1487 |
| 1457 DISALLOW_IMPLICIT_CONSTRUCTORS(JSReceiver); | 1488 DISALLOW_IMPLICIT_CONSTRUCTORS(JSReceiver); |
| 1458 }; | 1489 }; |
| 1459 | 1490 |
| 1460 // The JSObject describes real heap allocated JavaScript objects with | 1491 // The JSObject describes real heap allocated JavaScript objects with |
| 1461 // properties. | 1492 // properties. |
| 1462 // Note that the map of JSObject changes during execution to enable inline | 1493 // Note that the map of JSObject changes during execution to enable inline |
| 1463 // caching. | 1494 // caching. |
| 1464 class JSObject: public JSReceiver { | 1495 class JSObject: public JSReceiver { |
| 1465 public: | 1496 public: |
| 1466 enum ElementsKind { | |
| 1467 // The "fast" kind for tagged values. Must be first to make it possible | |
| 1468 // to efficiently check maps if they have fast elements. | |
| 1469 FAST_ELEMENTS, | |
| 1470 | |
| 1471 // The "fast" kind for unwrapped, non-tagged double values. | |
| 1472 FAST_DOUBLE_ELEMENTS, | |
| 1473 | |
| 1474 // The "slow" kind. | |
| 1475 DICTIONARY_ELEMENTS, | |
| 1476 NON_STRICT_ARGUMENTS_ELEMENTS, | |
| 1477 // The "fast" kind for external arrays | |
| 1478 EXTERNAL_BYTE_ELEMENTS, | |
| 1479 EXTERNAL_UNSIGNED_BYTE_ELEMENTS, | |
| 1480 EXTERNAL_SHORT_ELEMENTS, | |
| 1481 EXTERNAL_UNSIGNED_SHORT_ELEMENTS, | |
| 1482 EXTERNAL_INT_ELEMENTS, | |
| 1483 EXTERNAL_UNSIGNED_INT_ELEMENTS, | |
| 1484 EXTERNAL_FLOAT_ELEMENTS, | |
| 1485 EXTERNAL_DOUBLE_ELEMENTS, | |
| 1486 EXTERNAL_PIXEL_ELEMENTS, | |
| 1487 | |
| 1488 // Derived constants from ElementsKind | |
| 1489 FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND = EXTERNAL_BYTE_ELEMENTS, | |
| 1490 LAST_EXTERNAL_ARRAY_ELEMENTS_KIND = EXTERNAL_PIXEL_ELEMENTS, | |
| 1491 FIRST_ELEMENTS_KIND = FAST_ELEMENTS, | |
| 1492 LAST_ELEMENTS_KIND = EXTERNAL_PIXEL_ELEMENTS | |
| 1493 }; | |
| 1494 | |
| 1495 static const int kElementsKindCount = | |
| 1496 LAST_ELEMENTS_KIND - FIRST_ELEMENTS_KIND + 1; | |
| 1497 | |
| 1498 // [properties]: Backing storage for properties. | 1497 // [properties]: Backing storage for properties. |
| 1499 // properties is a FixedArray in the fast case and a Dictionary in the | 1498 // properties is a FixedArray in the fast case and a Dictionary in the |
| 1500 // slow case. | 1499 // slow case. |
| 1501 DECL_ACCESSORS(properties, FixedArray) // Get and set fast properties. | 1500 DECL_ACCESSORS(properties, FixedArray) // Get and set fast properties. |
| 1502 inline void initialize_properties(); | 1501 inline void initialize_properties(); |
| 1503 inline bool HasFastProperties(); | 1502 inline bool HasFastProperties(); |
| 1504 inline StringDictionary* property_dictionary(); // Gets slow properties. | 1503 inline StringDictionary* property_dictionary(); // Gets slow properties. |
| 1505 | 1504 |
| 1506 // [elements]: The elements (properties with names that are integers). | 1505 // [elements]: The elements (properties with names that are integers). |
| 1507 // | 1506 // |
| (...skipping 2505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4013 set_bit_field(bit_field() | (1 << kHasInstanceCallHandler)); | 4012 set_bit_field(bit_field() | (1 << kHasInstanceCallHandler)); |
| 4014 } | 4013 } |
| 4015 | 4014 |
| 4016 inline bool has_instance_call_handler() { | 4015 inline bool has_instance_call_handler() { |
| 4017 return ((1 << kHasInstanceCallHandler) & bit_field()) != 0; | 4016 return ((1 << kHasInstanceCallHandler) & bit_field()) != 0; |
| 4018 } | 4017 } |
| 4019 | 4018 |
| 4020 inline void set_is_extensible(bool value); | 4019 inline void set_is_extensible(bool value); |
| 4021 inline bool is_extensible(); | 4020 inline bool is_extensible(); |
| 4022 | 4021 |
| 4023 inline void set_elements_kind(JSObject::ElementsKind elements_kind) { | 4022 inline void set_elements_kind(ElementsKind elements_kind) { |
| 4024 ASSERT(elements_kind < JSObject::kElementsKindCount); | 4023 ASSERT(elements_kind < kElementsKindCount); |
| 4025 ASSERT(JSObject::kElementsKindCount <= (1 << kElementsKindBitCount)); | 4024 ASSERT(kElementsKindCount <= (1 << kElementsKindBitCount)); |
| 4026 set_bit_field2((bit_field2() & ~kElementsKindMask) | | 4025 set_bit_field2((bit_field2() & ~kElementsKindMask) | |
| 4027 (elements_kind << kElementsKindShift)); | 4026 (elements_kind << kElementsKindShift)); |
| 4028 ASSERT(this->elements_kind() == elements_kind); | 4027 ASSERT(this->elements_kind() == elements_kind); |
| 4029 } | 4028 } |
| 4030 | 4029 |
| 4031 inline JSObject::ElementsKind elements_kind() { | 4030 inline ElementsKind elements_kind() { |
| 4032 return static_cast<JSObject::ElementsKind>( | 4031 return static_cast<ElementsKind>( |
| 4033 (bit_field2() & kElementsKindMask) >> kElementsKindShift); | 4032 (bit_field2() & kElementsKindMask) >> kElementsKindShift); |
| 4034 } | 4033 } |
| 4035 | 4034 |
| 4036 // Tells whether the instance has fast elements. | 4035 // Tells whether the instance has fast elements. |
| 4037 // Equivalent to instance->GetElementsKind() == FAST_ELEMENTS. | 4036 // Equivalent to instance->GetElementsKind() == FAST_ELEMENTS. |
| 4038 inline bool has_fast_elements() { | 4037 inline bool has_fast_elements() { |
| 4039 return elements_kind() == JSObject::FAST_ELEMENTS; | 4038 return elements_kind() == FAST_ELEMENTS; |
| 4040 } | 4039 } |
| 4041 | 4040 |
| 4042 inline bool has_fast_double_elements() { | 4041 inline bool has_fast_double_elements() { |
| 4043 return elements_kind() == JSObject::FAST_DOUBLE_ELEMENTS; | 4042 return elements_kind() == FAST_DOUBLE_ELEMENTS; |
| 4044 } | 4043 } |
| 4045 | 4044 |
| 4046 inline bool has_external_array_elements() { | 4045 inline bool has_external_array_elements() { |
| 4047 JSObject::ElementsKind kind(elements_kind()); | 4046 ElementsKind kind(elements_kind()); |
| 4048 return kind >= JSObject::FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND && | 4047 return kind >= FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND && |
| 4049 kind <= JSObject::LAST_EXTERNAL_ARRAY_ELEMENTS_KIND; | 4048 kind <= LAST_EXTERNAL_ARRAY_ELEMENTS_KIND; |
| 4050 } | 4049 } |
| 4051 | 4050 |
| 4052 inline bool has_dictionary_elements() { | 4051 inline bool has_dictionary_elements() { |
| 4053 return elements_kind() == JSObject::DICTIONARY_ELEMENTS; | 4052 return elements_kind() == DICTIONARY_ELEMENTS; |
| 4054 } | 4053 } |
| 4055 | 4054 |
| 4056 // Tells whether the map is attached to SharedFunctionInfo | 4055 // Tells whether the map is attached to SharedFunctionInfo |
| 4057 // (for inobject slack tracking). | 4056 // (for inobject slack tracking). |
| 4058 inline void set_attached_to_shared_function_info(bool value); | 4057 inline void set_attached_to_shared_function_info(bool value); |
| 4059 | 4058 |
| 4060 inline bool attached_to_shared_function_info(); | 4059 inline bool attached_to_shared_function_info(); |
| 4061 | 4060 |
| 4062 // Tells whether the map is shared between objects that may have different | 4061 // Tells whether the map is shared between objects that may have different |
| 4063 // behavior. If true, the map should never be modified, instead a clone | 4062 // behavior. If true, the map should never be modified, instead a clone |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4315 static const int kAttachedToSharedFunctionInfo = 3; | 4314 static const int kAttachedToSharedFunctionInfo = 3; |
| 4316 // No bits can be used after kElementsKindFirstBit, they are all reserved for | 4315 // No bits can be used after kElementsKindFirstBit, they are all reserved for |
| 4317 // storing ElementKind. for anything other than storing the ElementKind. | 4316 // storing ElementKind. for anything other than storing the ElementKind. |
| 4318 static const int kElementsKindShift = 4; | 4317 static const int kElementsKindShift = 4; |
| 4319 static const int kElementsKindBitCount = 4; | 4318 static const int kElementsKindBitCount = 4; |
| 4320 | 4319 |
| 4321 // Derived values from bit field 2 | 4320 // Derived values from bit field 2 |
| 4322 static const int kElementsKindMask = (-1 << kElementsKindShift) & | 4321 static const int kElementsKindMask = (-1 << kElementsKindShift) & |
| 4323 ((1 << (kElementsKindShift + kElementsKindBitCount)) - 1); | 4322 ((1 << (kElementsKindShift + kElementsKindBitCount)) - 1); |
| 4324 static const int8_t kMaximumBitField2FastElementValue = static_cast<int8_t>( | 4323 static const int8_t kMaximumBitField2FastElementValue = static_cast<int8_t>( |
| 4325 (JSObject::FAST_ELEMENTS + 1) << Map::kElementsKindShift) - 1; | 4324 (FAST_ELEMENTS + 1) << Map::kElementsKindShift) - 1; |
| 4326 | 4325 |
| 4327 // Bit positions for bit field 3 | 4326 // Bit positions for bit field 3 |
| 4328 static const int kIsShared = 0; | 4327 static const int kIsShared = 0; |
| 4329 | 4328 |
| 4330 // Layout of the default cache. It holds alternating name and code objects. | 4329 // Layout of the default cache. It holds alternating name and code objects. |
| 4331 static const int kCodeCacheEntrySize = 2; | 4330 static const int kCodeCacheEntrySize = 2; |
| 4332 static const int kCodeCacheEntryNameOffset = 0; | 4331 static const int kCodeCacheEntryNameOffset = 0; |
| 4333 static const int kCodeCacheEntryCodeOffset = 1; | 4332 static const int kCodeCacheEntryCodeOffset = 1; |
| 4334 | 4333 |
| 4335 typedef FixedBodyDescriptor<kPointerFieldsBeginOffset, | 4334 typedef FixedBodyDescriptor<kPointerFieldsBeginOffset, |
| (...skipping 3120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7456 } else { | 7455 } else { |
| 7457 value &= ~(1 << bit_position); | 7456 value &= ~(1 << bit_position); |
| 7458 } | 7457 } |
| 7459 return value; | 7458 return value; |
| 7460 } | 7459 } |
| 7461 }; | 7460 }; |
| 7462 | 7461 |
| 7463 } } // namespace v8::internal | 7462 } } // namespace v8::internal |
| 7464 | 7463 |
| 7465 #endif // V8_OBJECTS_H_ | 7464 #endif // V8_OBJECTS_H_ |
| OLD | NEW |