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_INL_H_ | 5 #ifndef V8_FIELD_INDEX_INL_H_ |
6 #define V8_FIELD_INDEX_INL_H_ | 6 #define V8_FIELD_INDEX_INL_H_ |
7 | 7 |
8 #include "src/field-index.h" | 8 #include "src/field-index.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 21 matching lines...) Expand all Loading... |
32 first_inobject_offset = map->GetInObjectPropertyOffset(0); | 32 first_inobject_offset = map->GetInObjectPropertyOffset(0); |
33 } else { | 33 } else { |
34 first_inobject_offset = FixedArray::kHeaderSize; | 34 first_inobject_offset = FixedArray::kHeaderSize; |
35 property_index -= inobject_properties; | 35 property_index -= inobject_properties; |
36 } | 36 } |
37 return FieldIndex(is_inobject, | 37 return FieldIndex(is_inobject, |
38 property_index + first_inobject_offset / kPointerSize, | 38 property_index + first_inobject_offset / kPointerSize, |
39 is_double, inobject_properties, first_inobject_offset); | 39 is_double, inobject_properties, first_inobject_offset); |
40 } | 40 } |
41 | 41 |
42 | 42 // Takes an index as computed by GetLoadByFieldIndex and reconstructs a |
43 // Takes an index as computed by GetLoadFieldByIndex and reconstructs a | |
44 // FieldIndex object from it. | 43 // FieldIndex object from it. |
45 inline FieldIndex FieldIndex::ForLoadByFieldIndex(Map* map, int orig_index) { | 44 inline FieldIndex FieldIndex::ForLoadByFieldIndex(Map* map, int orig_index) { |
46 int field_index = orig_index; | 45 int field_index = orig_index; |
47 int is_inobject = true; | 46 int is_inobject = true; |
48 bool is_double = field_index & 1; | 47 bool is_double = field_index & 1; |
49 int first_inobject_offset = 0; | 48 int first_inobject_offset = 0; |
50 field_index >>= 1; | 49 field_index >>= 1; |
51 if (field_index < 0) { | 50 if (field_index < 0) { |
52 field_index = -(field_index + 1); | 51 field_index = -(field_index + 1); |
53 is_inobject = false; | 52 is_inobject = false; |
(...skipping 24 matching lines...) Expand all Loading... |
78 if (is_inobject()) { | 77 if (is_inobject()) { |
79 result -= JSObject::kHeaderSize / kPointerSize; | 78 result -= JSObject::kHeaderSize / kPointerSize; |
80 } else { | 79 } else { |
81 result -= FixedArray::kHeaderSize / kPointerSize; | 80 result -= FixedArray::kHeaderSize / kPointerSize; |
82 result = -result - 1; | 81 result = -result - 1; |
83 } | 82 } |
84 result <<= 1; | 83 result <<= 1; |
85 return is_double() ? (result | 1) : result; | 84 return is_double() ? (result | 1) : result; |
86 } | 85 } |
87 | 86 |
| 87 // Takes an offset as computed by GetLoadByFieldOffset and reconstructs a |
| 88 // FieldIndex object from it. |
| 89 inline FieldIndex FieldIndex::ForLoadByFieldOffset(Map* map, int offset) { |
| 90 bool is_double = offset & 1; |
| 91 int field_index = (offset >> 1) / kPointerSize; |
| 92 int is_inobject = true; |
| 93 int first_inobject_offset = 0; |
| 94 if (field_index < 0) { |
| 95 field_index = -field_index; |
| 96 is_inobject = false; |
| 97 first_inobject_offset = FixedArray::kHeaderSize; |
| 98 } else { |
| 99 first_inobject_offset = |
| 100 map->IsJSObjectMap() ? map->GetInObjectPropertyOffset(0) : 0; |
| 101 } |
| 102 int inobject_properties = |
| 103 map->IsJSObjectMap() ? map->GetInObjectProperties() : 0; |
| 104 FieldIndex result(is_inobject, field_index, is_double, inobject_properties, |
| 105 first_inobject_offset); |
| 106 DCHECK(result.GetLoadByFieldOffset() == offset); |
| 107 return result; |
| 108 } |
| 109 |
| 110 // Returns the offset format consumed by TurboFan stubs: |
| 111 // In-object: zero-based from object start, |
| 112 // out-of-object: zero-based from FixedArray start. |
| 113 inline int FieldIndex::GetLoadByFieldOffset() const { |
| 114 // For efficiency, stubs consume an offset that is optimized for quick |
| 115 // access. If the property is in-object, the offset is positive. |
| 116 // If it's out-of-object, the encoded offset is -raw_offset. |
| 117 // In either case, the offset itself is shifted up by one bit, the lower-most |
| 118 // bit signifying if the field is a mutable double box (1) or not (0). |
| 119 int result = index() << kPointerSizeLog2; |
| 120 if (!is_inobject()) result = -result; |
| 121 return (result << 1) | (is_double() ? 1 : 0); |
| 122 } |
88 | 123 |
89 inline FieldIndex FieldIndex::ForDescriptor(Map* map, int descriptor_index) { | 124 inline FieldIndex FieldIndex::ForDescriptor(Map* map, int descriptor_index) { |
90 PropertyDetails details = | 125 PropertyDetails details = |
91 map->instance_descriptors()->GetDetails(descriptor_index); | 126 map->instance_descriptors()->GetDetails(descriptor_index); |
92 int field_index = details.field_index(); | 127 int field_index = details.field_index(); |
93 return ForPropertyIndex(map, field_index, | 128 return ForPropertyIndex(map, field_index, |
94 details.representation().IsDouble()); | 129 details.representation().IsDouble()); |
95 } | 130 } |
96 | 131 |
97 | 132 |
(...skipping 17 matching lines...) Expand all Loading... |
115 } else { | 150 } else { |
116 return property_index(); | 151 return property_index(); |
117 } | 152 } |
118 } | 153 } |
119 | 154 |
120 | 155 |
121 } // namespace internal | 156 } // namespace internal |
122 } // namespace v8 | 157 } // namespace v8 |
123 | 158 |
124 #endif | 159 #endif |
OLD | NEW |