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 { |
11 namespace internal { | 11 namespace internal { |
12 | 12 |
13 | 13 |
14 inline FieldIndex FieldIndex::ForInObjectOffset(int offset, Map* map) { | 14 inline FieldIndex FieldIndex::ForInObjectOffset(int offset, Map* map) { |
15 DCHECK((offset % kPointerSize) == 0); | 15 DCHECK((offset % kPointerSize) == 0); |
16 int index = offset / kPointerSize; | 16 int index = offset / kPointerSize; |
17 DCHECK(map == NULL || | 17 DCHECK(map == NULL || |
18 index < (map->GetInObjectPropertyOffset(0) / kPointerSize + | 18 index < (map->GetInObjectPropertyOffset(0) / kPointerSize + |
19 map->inobject_properties())); | 19 map->GetInObjectProperties())); |
20 return FieldIndex(true, index, false, 0, 0, true); | 20 return FieldIndex(true, index, false, 0, 0, true); |
21 } | 21 } |
22 | 22 |
23 | 23 |
24 inline FieldIndex FieldIndex::ForPropertyIndex(Map* map, | 24 inline FieldIndex FieldIndex::ForPropertyIndex(Map* map, |
25 int property_index, | 25 int property_index, |
26 bool is_double) { | 26 bool is_double) { |
27 DCHECK(map->instance_type() >= FIRST_NONSTRING_TYPE); | 27 DCHECK(map->instance_type() >= FIRST_NONSTRING_TYPE); |
28 int inobject_properties = map->inobject_properties(); | 28 int inobject_properties = map->GetInObjectProperties(); |
29 bool is_inobject = property_index < inobject_properties; | 29 bool is_inobject = property_index < inobject_properties; |
30 int first_inobject_offset; | 30 int first_inobject_offset; |
31 if (is_inobject) { | 31 if (is_inobject) { |
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, |
(...skipping 12 matching lines...) Expand all Loading... |
51 if (field_index < 0) { | 51 if (field_index < 0) { |
52 field_index = -(field_index + 1); | 52 field_index = -(field_index + 1); |
53 is_inobject = false; | 53 is_inobject = false; |
54 first_inobject_offset = FixedArray::kHeaderSize; | 54 first_inobject_offset = FixedArray::kHeaderSize; |
55 field_index += FixedArray::kHeaderSize / kPointerSize; | 55 field_index += FixedArray::kHeaderSize / kPointerSize; |
56 } else { | 56 } else { |
57 first_inobject_offset = map->GetInObjectPropertyOffset(0); | 57 first_inobject_offset = map->GetInObjectPropertyOffset(0); |
58 field_index += JSObject::kHeaderSize / kPointerSize; | 58 field_index += JSObject::kHeaderSize / kPointerSize; |
59 } | 59 } |
60 FieldIndex result(is_inobject, field_index, is_double, | 60 FieldIndex result(is_inobject, field_index, is_double, |
61 map->inobject_properties(), first_inobject_offset); | 61 map->GetInObjectProperties(), first_inobject_offset); |
62 DCHECK(result.GetLoadByFieldIndex() == orig_index); | 62 DCHECK(result.GetLoadByFieldIndex() == orig_index); |
63 return result; | 63 return result; |
64 } | 64 } |
65 | 65 |
66 | 66 |
67 // Returns the index format accepted by the HLoadFieldByIndex instruction. | 67 // Returns the index format accepted by the HLoadFieldByIndex instruction. |
68 // (In-object: zero-based from (object start + JSObject::kHeaderSize), | 68 // (In-object: zero-based from (object start + JSObject::kHeaderSize), |
69 // out-of-object: zero-based from FixedArray::kHeaderSize.) | 69 // out-of-object: zero-based from FixedArray::kHeaderSize.) |
70 inline int FieldIndex::GetLoadByFieldIndex() const { | 70 inline int FieldIndex::GetLoadByFieldIndex() const { |
71 // For efficiency, the LoadByFieldIndex instruction takes an index that is | 71 // For efficiency, the LoadByFieldIndex instruction takes an index that is |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 return GetLoadByFieldIndex(); | 115 return GetLoadByFieldIndex(); |
116 } else { | 116 } else { |
117 return property_index(); | 117 return property_index(); |
118 } | 118 } |
119 } | 119 } |
120 | 120 |
121 | 121 |
122 } } // namespace v8::internal | 122 } } // namespace v8::internal |
123 | 123 |
124 #endif | 124 #endif |
OLD | NEW |