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_INL_H_
6 #define V8_FIELD_INDEX_INL_H_
8 #include "src/field-index.h"
14 inline FieldIndex FieldIndex::ForInObjectOffset(int offset, Map* map) {
15 DCHECK((offset % kPointerSize) == 0);
16 int index = offset / kPointerSize;
18 index < (map->GetInObjectPropertyOffset(0) / kPointerSize +
19 map->GetInObjectProperties()));
20 return FieldIndex(true, index, false, 0, 0, true);
24 inline FieldIndex FieldIndex::ForPropertyIndex(Map* map,
27 DCHECK(map->instance_type() >= FIRST_NONSTRING_TYPE);
28 int inobject_properties = map->GetInObjectProperties();
29 bool is_inobject = property_index < inobject_properties;
30 int first_inobject_offset;
32 first_inobject_offset = map->GetInObjectPropertyOffset(0);
34 first_inobject_offset = FixedArray::kHeaderSize;
35 property_index -= inobject_properties;
37 return FieldIndex(is_inobject,
38 property_index + first_inobject_offset / kPointerSize,
39 is_double, inobject_properties, first_inobject_offset);
43 // Takes an index as computed by GetLoadFieldByIndex and reconstructs a
44 // FieldIndex object from it.
45 inline FieldIndex FieldIndex::ForLoadByFieldIndex(Map* map, int orig_index) {
46 int field_index = orig_index;
47 int is_inobject = true;
48 bool is_double = field_index & 1;
49 int first_inobject_offset = 0;
51 if (field_index < 0) {
52 field_index = -(field_index + 1);
54 first_inobject_offset = FixedArray::kHeaderSize;
55 field_index += FixedArray::kHeaderSize / kPointerSize;
57 first_inobject_offset = map->GetInObjectPropertyOffset(0);
58 field_index += JSObject::kHeaderSize / kPointerSize;
60 FieldIndex result(is_inobject, field_index, is_double,
61 map->GetInObjectProperties(), first_inobject_offset);
62 DCHECK(result.GetLoadByFieldIndex() == orig_index);
67 // Returns the index format accepted by the HLoadFieldByIndex instruction.
68 // (In-object: zero-based from (object start + JSObject::kHeaderSize),
69 // out-of-object: zero-based from FixedArray::kHeaderSize.)
70 inline int FieldIndex::GetLoadByFieldIndex() const {
71 // For efficiency, the LoadByFieldIndex instruction takes an index that is
72 // optimized for quick access. If the property is inline, the index is
73 // positive. If it's out-of-line, the encoded index is -raw_index - 1 to
74 // disambiguate the zero out-of-line index from the zero inobject case.
75 // The index itself is shifted up by one bit, the lower-most bit
76 // signifying if the field is a mutable double box (1) or not (0).
79 result -= JSObject::kHeaderSize / kPointerSize;
81 result -= FixedArray::kHeaderSize / kPointerSize;
85 return is_double() ? (result | 1) : result;
89 inline FieldIndex FieldIndex::ForDescriptor(Map* map, int descriptor_index) {
90 PropertyDetails details =
91 map->instance_descriptors()->GetDetails(descriptor_index);
92 int field_index = details.field_index();
93 return ForPropertyIndex(map, field_index,
94 details.representation().IsDouble());
98 inline FieldIndex FieldIndex::ForKeyedLookupCacheIndex(Map* map, int index) {
99 if (FLAG_compiled_keyed_generic_loads) {
100 return ForLoadByFieldIndex(map, index);
102 return ForPropertyIndex(map, index);
107 inline FieldIndex FieldIndex::FromFieldAccessStubKey(int key) {
108 return FieldIndex(key);
112 inline int FieldIndex::GetKeyedLookupCacheIndex() const {
113 if (FLAG_compiled_keyed_generic_loads) {
114 return GetLoadByFieldIndex();
116 return property_index();
121 } } // namespace v8::internal