| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef V8_FIELD_INDEX_H_ | |
| 6 #define V8_FIELD_INDEX_H_ | |
| 7 | |
| 8 #include "src/utils.h" | |
| 9 #include "src/property-details.h" | |
| 10 | |
| 11 namespace v8 { | |
| 12 namespace internal { | |
| 13 | |
| 14 class Map; | |
| 15 | |
| 16 // Wrapper class to hold a field index, usually but not necessarily generated | |
| 17 // from a property index. When available, the wrapper class captures additional | |
| 18 // information to allow the field index to be translated back into the property | |
| 19 // index it was originally generated from. | |
| 20 class FieldIndex V8_FINAL { | |
| 21 public: | |
| 22 static FieldIndex ForPropertyIndex(Map* map, | |
| 23 int index, | |
| 24 bool is_double = false); | |
| 25 static FieldIndex ForInObjectOffset(int offset, Map* map = NULL); | |
| 26 static FieldIndex ForLookupResult(const LookupResult* result); | |
| 27 static FieldIndex ForDescriptor(Map* map, int descriptor_index); | |
| 28 static FieldIndex ForLoadByFieldIndex(Map* map, int index); | |
| 29 static FieldIndex ForKeyedLookupCacheIndex(Map* map, int index) { | |
| 30 return ForPropertyIndex(map, index); | |
| 31 } | |
| 32 | |
| 33 bool is_inobject() const { | |
| 34 return IsInObjectBits::decode(bit_field_); | |
| 35 } | |
| 36 | |
| 37 bool is_double() const { | |
| 38 return IsDoubleBits::decode(bit_field_); | |
| 39 } | |
| 40 | |
| 41 int offset() const { | |
| 42 return index() * kPointerSize; | |
| 43 } | |
| 44 | |
| 45 int index() const { | |
| 46 return IndexBits::decode(bit_field_); | |
| 47 } | |
| 48 | |
| 49 int outobject_array_index() const { | |
| 50 ASSERT(!is_inobject()); | |
| 51 return index() - first_inobject_property_offset() / kPointerSize; | |
| 52 } | |
| 53 | |
| 54 int property_index() const { | |
| 55 ASSERT(!IsHiddenField::decode(bit_field_)); | |
| 56 int result = index() - first_inobject_property_offset() / kPointerSize; | |
| 57 if (!is_inobject()) { | |
| 58 result += InObjectPropertyBits::decode(bit_field_); | |
| 59 } | |
| 60 return result; | |
| 61 } | |
| 62 | |
| 63 int GetLoadByFieldIndex() const { | |
| 64 // For efficiency, the LoadByFieldIndex instruction takes an index that is | |
| 65 // optimized for quick access. If the property is inline, the index is | |
| 66 // positive. If it's out-of-line, the encoded index is -raw_index - 1 to | |
| 67 // disambiguate the zero out-of-line index from the zero inobject case. | |
| 68 // The index itself is shifted up by one bit, the lower-most bit | |
| 69 // signifying if the field is a mutable double box (1) or not (0). | |
| 70 int result = index() - first_inobject_property_offset() / kPointerSize; | |
| 71 if (!is_inobject()) { | |
| 72 result = -result - 1; | |
| 73 } | |
| 74 result <<= 1; | |
| 75 return is_double() ? (result | 1) : result; | |
| 76 } | |
| 77 | |
| 78 int GetKeyedLookupCacheIndex() const { | |
| 79 return property_index(); | |
| 80 } | |
| 81 | |
| 82 int GetLoadFieldStubKey() const { | |
| 83 return bit_field_ & | |
| 84 (IsInObjectBits::kMask | IsDoubleBits::kMask | IndexBits::kMask); | |
| 85 } | |
| 86 | |
| 87 private: | |
| 88 FieldIndex(bool is_inobject, int local_index, bool is_double, | |
| 89 int inobject_properties, int first_inobject_property_offset, | |
| 90 bool is_hidden = false) { | |
| 91 ASSERT((first_inobject_property_offset & (kPointerSize - 1)) == 0); | |
| 92 bit_field_ = IsInObjectBits::encode(is_inobject) | | |
| 93 IsDoubleBits::encode(is_double) | | |
| 94 FirstInobjectPropertyOffsetBits::encode(first_inobject_property_offset) | | |
| 95 IsHiddenField::encode(is_hidden) | | |
| 96 IndexBits::encode(local_index) | | |
| 97 InObjectPropertyBits::encode(inobject_properties); | |
| 98 } | |
| 99 | |
| 100 int first_inobject_property_offset() const { | |
| 101 ASSERT(!IsHiddenField::decode(bit_field_)); | |
| 102 return FirstInobjectPropertyOffsetBits::decode(bit_field_); | |
| 103 } | |
| 104 | |
| 105 static const int kIndexBitsSize = kDescriptorIndexBitCount + 1; | |
| 106 | |
| 107 class IndexBits: public BitField<int, 0, kIndexBitsSize> {}; | |
| 108 class IsInObjectBits: public BitField<bool, IndexBits::kNext, 1> {}; | |
| 109 class IsDoubleBits: public BitField<bool, IsInObjectBits::kNext, 1> {}; | |
| 110 class InObjectPropertyBits: public BitField<int, IsDoubleBits::kNext, | |
| 111 kDescriptorIndexBitCount> {}; | |
| 112 class FirstInobjectPropertyOffsetBits: | |
| 113 public BitField<int, InObjectPropertyBits::kNext, 7> {}; | |
| 114 class IsHiddenField: | |
| 115 public BitField<bool, FirstInobjectPropertyOffsetBits::kNext, 1> {}; | |
| 116 STATIC_ASSERT(IsHiddenField::kNext <= 32); | |
| 117 | |
| 118 int bit_field_; | |
| 119 }; | |
| 120 | |
| 121 } } // namespace v8::internal | |
| 122 | |
| 123 #endif | |
| OLD | NEW |