Line data Source code
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.
4 :
5 : #ifndef V8_FIELD_INDEX_INL_H_
6 : #define V8_FIELD_INDEX_INL_H_
7 :
8 : #include "src/field-index.h"
9 : #include "src/objects/descriptor-array.h"
10 :
11 : namespace v8 {
12 : namespace internal {
13 :
14 :
15 : inline FieldIndex FieldIndex::ForInObjectOffset(int offset, Map* map) {
16 : DCHECK((offset % kPointerSize) == 0);
17 193132 : int index = offset / kPointerSize;
18 : DCHECK(map == NULL ||
19 : index < (map->GetInObjectPropertyOffset(0) / kPointerSize +
20 : map->GetInObjectProperties()));
21 : return FieldIndex(true, index, false, 0, 0, true);
22 : }
23 :
24 :
25 262410993 : inline FieldIndex FieldIndex::ForPropertyIndex(Map* map,
26 : int property_index,
27 : bool is_double) {
28 : DCHECK(map->instance_type() >= FIRST_NONSTRING_TYPE);
29 : int inobject_properties = map->GetInObjectProperties();
30 262410993 : bool is_inobject = property_index < inobject_properties;
31 : int first_inobject_offset;
32 262410993 : if (is_inobject) {
33 158595503 : first_inobject_offset = map->GetInObjectPropertyOffset(0);
34 : } else {
35 : first_inobject_offset = FixedArray::kHeaderSize;
36 103815490 : property_index -= inobject_properties;
37 : }
38 : return FieldIndex(is_inobject,
39 262410994 : property_index + first_inobject_offset / kPointerSize,
40 524821988 : is_double, inobject_properties, first_inobject_offset);
41 : }
42 :
43 : // Takes an index as computed by GetLoadByFieldIndex and reconstructs a
44 : // FieldIndex object from it.
45 14 : inline FieldIndex FieldIndex::ForLoadByFieldIndex(Map* map, int orig_index) {
46 : int field_index = orig_index;
47 : bool is_inobject = true;
48 14 : bool is_double = field_index & 1;
49 : int first_inobject_offset = 0;
50 14 : field_index >>= 1;
51 14 : if (field_index < 0) {
52 0 : field_index = -(field_index + 1);
53 : is_inobject = false;
54 : first_inobject_offset = FixedArray::kHeaderSize;
55 0 : field_index += FixedArray::kHeaderSize / kPointerSize;
56 : } else {
57 14 : first_inobject_offset = map->GetInObjectPropertyOffset(0);
58 14 : field_index += JSObject::kHeaderSize / kPointerSize;
59 : }
60 : FieldIndex result(is_inobject, field_index, is_double,
61 : map->GetInObjectProperties(), first_inobject_offset);
62 : DCHECK(result.GetLoadByFieldIndex() == orig_index);
63 14 : return result;
64 : }
65 :
66 :
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 608070 : 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).
77 : int result = index();
78 608070 : if (is_inobject()) {
79 443938 : result -= JSObject::kHeaderSize / kPointerSize;
80 : } else {
81 164132 : result -= FixedArray::kHeaderSize / kPointerSize;
82 164132 : result = -result - 1;
83 : }
84 608070 : result <<= 1;
85 608070 : return is_double() ? (result | 1) : result;
86 : }
87 :
88 221933757 : inline FieldIndex FieldIndex::ForDescriptor(Map* map, int descriptor_index) {
89 : PropertyDetails details =
90 221933757 : map->instance_descriptors()->GetDetails(descriptor_index);
91 : int field_index = details.field_index();
92 : return ForPropertyIndex(map, field_index,
93 221933749 : details.representation().IsDouble());
94 : }
95 :
96 : inline FieldIndex FieldIndex::FromFieldAccessStubKey(int key) {
97 : return FieldIndex(key);
98 : }
99 :
100 : } // namespace internal
101 : } // namespace v8
102 :
103 : #endif
|