Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Side by Side Diff: src/field-index.h

Issue 300283002: Introduce FieldIndex to unify and abstract property/field offset (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix nit Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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_H_
6 #define V8_FIELD_INDEX_H_
7
8 #include "src/utils.h"
9 #include "src/property-details.h"
10
11 namespace v8 {
12 namespace internal {
13
14 class Map;
15
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 V8_FINAL {
21 public:
22 static FieldIndex ForPropertyIndex(Map* map,
23 int index,
24 bool is_double = false);
25 static FieldIndex ForInObjectOffset(int offset, Map* map = NULL);
26 static FieldIndex ForLookupResult(const LookupResult* result);
27 static FieldIndex ForDescriptor(Map* map, int descriptor_index);
28 static FieldIndex ForKeyedLookupCacheIndex(Map* map, int index) {
29 return ForPropertyIndex(map, index);
30 }
31 static FieldIndex ForLoadByFieldIndex(Map* map, int index);
32
33 bool is_inobject() const {
34 return IsInObjectBits::decode(bit_field_);
35 }
36
37 bool is_double() const {
38 return IsDoubleBits::decode(bit_field_);
39 }
40
41 int offset() const {
42 return index() * kPointerSize;
43 }
44
45 int index() const {
46 return IndexBits::decode(bit_field_);
47 }
48
49 int property_index() const {
50 return index() - header_size() / kPointerSize;
51 }
52
53 int GetLoadByFieldIndex() const {
54 // For efficiency, the LoadByFieldIndex instruction takes an index that is
55 // optimized for quick access. If the property is inline, the index is
56 // positive. If it's out-of-line, the encoded index is -raw_index - 1 to
57 // disambiguate the zero out-of-line index from the zero inobject case.
58 // The index itself is shifted up by one bit, the lower-most bit
59 // signifying if the field is a mutable double box (1) or not (0).
60 int result = property_index();
61 if (!is_inobject()) {
62 result = -result - 1;
63 }
64 result <<= 1;
65 return is_double() ? (result | 1) : result;
66 }
67
68 int GetKeyedLookupCacheIndex() const {
69 int result = property_index();
70 if (!is_inobject()) {
71 result += InObjectPropertyBits::decode(bit_field_);
72 }
73 return result;
74 }
75
76 int GetLoadFieldStubKey() const {
77 return bit_field_ &
78 (IsInObjectBits::kMask | IsDoubleBits::kMask | IndexBits::kMask);
79 }
80
81 private:
82 FieldIndex(bool is_inobject, int local_index, bool is_double,
83 int inobject_properties, int header_size,
84 bool is_hidden = false) {
85 ASSERT((header_size & (kPointerSize - 1)) == 0);
86 bit_field_ = IsInObjectBits::encode(is_inobject) |
87 IsDoubleBits::encode(is_double) |
88 HeaderSizeBits::encode(header_size) |
89 IsHiddenField::encode(is_hidden) |
90 IndexBits::encode(local_index) |
91 InObjectPropertyBits::encode(inobject_properties);
92 }
93
94 int header_size() const {
95 ASSERT(!IsHiddenField::decode(bit_field_));
96 return HeaderSizeBits::decode(bit_field_);
97 }
98
99 static const int kIndexBitsSize = kDescriptorIndexBitCount + 1;
100
101 class IndexBits : public BitField<int, 0, kIndexBitsSize> {};
102 class IsInObjectBits : public BitField<bool, IndexBits::kNext, 1> {};
103 class IsDoubleBits : public BitField<bool, IsInObjectBits::kNext, 1> {};
104 class InObjectPropertyBits : public BitField<int, IsDoubleBits::kNext,
105 kDescriptorIndexBitCount> {};
106 class HeaderSizeBits : public BitField<int, InObjectPropertyBits::kNext,
107 7> {};
108 class IsHiddenField : public BitField<bool, HeaderSizeBits::kNext, 1> {};
109 STATIC_ASSERT(IsHiddenField::kNext <= 32);
110
111 int bit_field_;
112 };
113
114 } } // namespace v8::internal
115
116 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698