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_
8 #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 FINAL {
22 static FieldIndex ForPropertyIndex(Map* map,
24 bool is_double = false);
25 static FieldIndex ForInObjectOffset(int offset, Map* map = NULL);
26 static FieldIndex ForDescriptor(Map* map, int descriptor_index);
27 static FieldIndex ForLoadByFieldIndex(Map* map, int index);
28 static FieldIndex ForKeyedLookupCacheIndex(Map* map, int index);
29 static FieldIndex FromFieldAccessStubKey(int key);
31 int GetLoadByFieldIndex() const;
33 bool is_inobject() const {
34 return IsInObjectBits::decode(bit_field_);
37 bool is_hidden_field() const { return IsHiddenField::decode(bit_field_); }
39 bool is_double() const {
40 return IsDoubleBits::decode(bit_field_);
44 return index() * kPointerSize;
47 // Zero-indexed from beginning of the object.
49 return IndexBits::decode(bit_field_);
52 int outobject_array_index() const {
53 DCHECK(!is_inobject());
54 return index() - first_inobject_property_offset() / kPointerSize;
57 // Zero-based from the first inobject property. Overflows to out-of-object
59 int property_index() const {
60 DCHECK(!is_hidden_field());
61 int result = index() - first_inobject_property_offset() / kPointerSize;
63 result += InObjectPropertyBits::decode(bit_field_);
68 int GetKeyedLookupCacheIndex() const;
70 int GetFieldAccessStubKey() const {
72 (IsInObjectBits::kMask | IsDoubleBits::kMask | IndexBits::kMask);
76 FieldIndex(bool is_inobject, int local_index, bool is_double,
77 int inobject_properties, int first_inobject_property_offset,
78 bool is_hidden = false) {
79 DCHECK((first_inobject_property_offset & (kPointerSize - 1)) == 0);
80 bit_field_ = IsInObjectBits::encode(is_inobject) |
81 IsDoubleBits::encode(is_double) |
82 FirstInobjectPropertyOffsetBits::encode(first_inobject_property_offset) |
83 IsHiddenField::encode(is_hidden) |
84 IndexBits::encode(local_index) |
85 InObjectPropertyBits::encode(inobject_properties);
88 explicit FieldIndex(int bit_field) : bit_field_(bit_field) {}
90 int first_inobject_property_offset() const {
91 DCHECK(!is_hidden_field());
92 return FirstInobjectPropertyOffsetBits::decode(bit_field_);
95 static const int kIndexBitsSize = kDescriptorIndexBitCount + 1;
97 // Index from beginning of object.
98 class IndexBits: public BitField<int, 0, kIndexBitsSize> {};
99 class IsInObjectBits: public BitField<bool, IndexBits::kNext, 1> {};
100 class IsDoubleBits: public BitField<bool, IsInObjectBits::kNext, 1> {};
101 // Number of inobject properties.
102 class InObjectPropertyBits
103 : public BitField<int, IsDoubleBits::kNext, kDescriptorIndexBitCount> {};
104 // Offset of first inobject property from beginning of object.
105 class FirstInobjectPropertyOffsetBits
106 : public BitField<int, InObjectPropertyBits::kNext, 7> {};
108 : public BitField<bool, FirstInobjectPropertyOffsetBits::kNext, 1> {};
109 STATIC_ASSERT(IsHiddenField::kNext <= 32);
114 } } // namespace v8::internal