| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_FIELD_INDEX_H_ | 5 #ifndef V8_FIELD_INDEX_H_ |
| 6 #define V8_FIELD_INDEX_H_ | 6 #define V8_FIELD_INDEX_H_ |
| 7 | 7 |
| 8 #include "src/property-details.h" | 8 #include "src/property-details.h" |
| 9 #include "src/utils.h" | 9 #include "src/utils.h" |
| 10 | 10 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 int offset() const { | 41 int offset() const { |
| 42 return index() * kPointerSize; | 42 return index() * kPointerSize; |
| 43 } | 43 } |
| 44 | 44 |
| 45 // Zero-indexed from beginning of the object. | 45 // Zero-indexed from beginning of the object. |
| 46 int index() const { | 46 int index() const { |
| 47 return IndexBits::decode(bit_field_); | 47 return IndexBits::decode(bit_field_); |
| 48 } | 48 } |
| 49 | 49 |
| 50 int outobject_array_index() const { | 50 int outobject_array_index() const { |
| 51 ASSERT(!is_inobject()); | 51 DCHECK(!is_inobject()); |
| 52 return index() - first_inobject_property_offset() / kPointerSize; | 52 return index() - first_inobject_property_offset() / kPointerSize; |
| 53 } | 53 } |
| 54 | 54 |
| 55 // Zero-based from the first inobject property. Overflows to out-of-object | 55 // Zero-based from the first inobject property. Overflows to out-of-object |
| 56 // properties. | 56 // properties. |
| 57 int property_index() const { | 57 int property_index() const { |
| 58 ASSERT(!IsHiddenField::decode(bit_field_)); | 58 DCHECK(!IsHiddenField::decode(bit_field_)); |
| 59 int result = index() - first_inobject_property_offset() / kPointerSize; | 59 int result = index() - first_inobject_property_offset() / kPointerSize; |
| 60 if (!is_inobject()) { | 60 if (!is_inobject()) { |
| 61 result += InObjectPropertyBits::decode(bit_field_); | 61 result += InObjectPropertyBits::decode(bit_field_); |
| 62 } | 62 } |
| 63 return result; | 63 return result; |
| 64 } | 64 } |
| 65 | 65 |
| 66 int GetKeyedLookupCacheIndex() const; | 66 int GetKeyedLookupCacheIndex() const; |
| 67 | 67 |
| 68 int GetLoadFieldStubKey() const { | 68 int GetLoadFieldStubKey() const { |
| 69 return bit_field_ & | 69 return bit_field_ & |
| 70 (IsInObjectBits::kMask | IsDoubleBits::kMask | IndexBits::kMask); | 70 (IsInObjectBits::kMask | IsDoubleBits::kMask | IndexBits::kMask); |
| 71 } | 71 } |
| 72 | 72 |
| 73 private: | 73 private: |
| 74 FieldIndex(bool is_inobject, int local_index, bool is_double, | 74 FieldIndex(bool is_inobject, int local_index, bool is_double, |
| 75 int inobject_properties, int first_inobject_property_offset, | 75 int inobject_properties, int first_inobject_property_offset, |
| 76 bool is_hidden = false) { | 76 bool is_hidden = false) { |
| 77 ASSERT((first_inobject_property_offset & (kPointerSize - 1)) == 0); | 77 DCHECK((first_inobject_property_offset & (kPointerSize - 1)) == 0); |
| 78 bit_field_ = IsInObjectBits::encode(is_inobject) | | 78 bit_field_ = IsInObjectBits::encode(is_inobject) | |
| 79 IsDoubleBits::encode(is_double) | | 79 IsDoubleBits::encode(is_double) | |
| 80 FirstInobjectPropertyOffsetBits::encode(first_inobject_property_offset) | | 80 FirstInobjectPropertyOffsetBits::encode(first_inobject_property_offset) | |
| 81 IsHiddenField::encode(is_hidden) | | 81 IsHiddenField::encode(is_hidden) | |
| 82 IndexBits::encode(local_index) | | 82 IndexBits::encode(local_index) | |
| 83 InObjectPropertyBits::encode(inobject_properties); | 83 InObjectPropertyBits::encode(inobject_properties); |
| 84 } | 84 } |
| 85 | 85 |
| 86 int first_inobject_property_offset() const { | 86 int first_inobject_property_offset() const { |
| 87 ASSERT(!IsHiddenField::decode(bit_field_)); | 87 DCHECK(!IsHiddenField::decode(bit_field_)); |
| 88 return FirstInobjectPropertyOffsetBits::decode(bit_field_); | 88 return FirstInobjectPropertyOffsetBits::decode(bit_field_); |
| 89 } | 89 } |
| 90 | 90 |
| 91 static const int kIndexBitsSize = kDescriptorIndexBitCount + 1; | 91 static const int kIndexBitsSize = kDescriptorIndexBitCount + 1; |
| 92 | 92 |
| 93 // Index from beginning of object. | 93 // Index from beginning of object. |
| 94 class IndexBits: public BitField<int, 0, kIndexBitsSize> {}; | 94 class IndexBits: public BitField<int, 0, kIndexBitsSize> {}; |
| 95 class IsInObjectBits: public BitField<bool, IndexBits::kNext, 1> {}; | 95 class IsInObjectBits: public BitField<bool, IndexBits::kNext, 1> {}; |
| 96 class IsDoubleBits: public BitField<bool, IsInObjectBits::kNext, 1> {}; | 96 class IsDoubleBits: public BitField<bool, IsInObjectBits::kNext, 1> {}; |
| 97 // Number of inobject properties. | 97 // Number of inobject properties. |
| 98 class InObjectPropertyBits | 98 class InObjectPropertyBits |
| 99 : public BitField<int, IsDoubleBits::kNext, kDescriptorIndexBitCount> {}; | 99 : public BitField<int, IsDoubleBits::kNext, kDescriptorIndexBitCount> {}; |
| 100 // Offset of first inobject property from beginning of object. | 100 // Offset of first inobject property from beginning of object. |
| 101 class FirstInobjectPropertyOffsetBits | 101 class FirstInobjectPropertyOffsetBits |
| 102 : public BitField<int, InObjectPropertyBits::kNext, 7> {}; | 102 : public BitField<int, InObjectPropertyBits::kNext, 7> {}; |
| 103 class IsHiddenField | 103 class IsHiddenField |
| 104 : public BitField<bool, FirstInobjectPropertyOffsetBits::kNext, 1> {}; | 104 : public BitField<bool, FirstInobjectPropertyOffsetBits::kNext, 1> {}; |
| 105 STATIC_ASSERT(IsHiddenField::kNext <= 32); | 105 STATIC_ASSERT(IsHiddenField::kNext <= 32); |
| 106 | 106 |
| 107 int bit_field_; | 107 int bit_field_; |
| 108 }; | 108 }; |
| 109 | 109 |
| 110 } } // namespace v8::internal | 110 } } // namespace v8::internal |
| 111 | 111 |
| 112 #endif | 112 #endif |
| OLD | NEW |