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.
5 #ifndef V8_FIELD_INDEX_H_
6 #define V8_FIELD_INDEX_H_
9 #include "src/property-details.h"
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 {
22 static FieldIndex ForPropertyIndex(Map* map,
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);
33 bool is_inobject() const {
34 return IsInObjectBits::decode(bit_field_);
37 bool is_double() const {
38 return IsDoubleBits::decode(bit_field_);
42 return index() * kPointerSize;
46 return IndexBits::decode(bit_field_);
49 int outobject_array_index() const {
50 ASSERT(!is_inobject());
51 return index() - first_inobject_property_offset() / kPointerSize;
54 int property_index() const {
55 ASSERT(!IsHiddenField::decode(bit_field_));
56 int result = index() - first_inobject_property_offset() / kPointerSize;
58 result += InObjectPropertyBits::decode(bit_field_);
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;
75 return is_double() ? (result | 1) : result;
78 int GetKeyedLookupCacheIndex() const {
79 return property_index();
82 int GetLoadFieldStubKey() const {
84 (IsInObjectBits::kMask | IsDoubleBits::kMask | IndexBits::kMask);
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);
100 int first_inobject_property_offset() const {
101 ASSERT(!IsHiddenField::decode(bit_field_));
102 return FirstInobjectPropertyOffsetBits::decode(bit_field_);
105 static const int kIndexBitsSize = kDescriptorIndexBitCount + 1;
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> {};
115 public BitField<bool, FirstInobjectPropertyOffsetBits::kNext, 1> {};
116 STATIC_ASSERT(IsHiddenField::kNext <= 32);
121 } } // namespace v8::internal