OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 CALLBACKS = 3, | 69 CALLBACKS = 3, |
70 // Only in lookup results, not in descriptors. | 70 // Only in lookup results, not in descriptors. |
71 HANDLER = 4, | 71 HANDLER = 4, |
72 INTERCEPTOR = 5, | 72 INTERCEPTOR = 5, |
73 TRANSITION = 6, | 73 TRANSITION = 6, |
74 // Only used as a marker in LookupResult. | 74 // Only used as a marker in LookupResult. |
75 NONEXISTENT = 7 | 75 NONEXISTENT = 7 |
76 }; | 76 }; |
77 | 77 |
78 | 78 |
| 79 class Representation { |
| 80 public: |
| 81 enum Kind { |
| 82 kNone, |
| 83 kSmi, |
| 84 kInteger32, |
| 85 kDouble, |
| 86 kTagged, |
| 87 kExternal, |
| 88 kNumRepresentations |
| 89 }; |
| 90 |
| 91 Representation() : kind_(kNone) { } |
| 92 |
| 93 static Representation None() { return Representation(kNone); } |
| 94 static Representation Tagged() { return Representation(kTagged); } |
| 95 static Representation Smi() { return Representation(kSmi); } |
| 96 static Representation Integer32() { return Representation(kInteger32); } |
| 97 static Representation Double() { return Representation(kDouble); } |
| 98 static Representation External() { return Representation(kExternal); } |
| 99 |
| 100 static Representation FromKind(Kind kind) { return Representation(kind); } |
| 101 |
| 102 bool Equals(const Representation& other) { |
| 103 return kind_ == other.kind_; |
| 104 } |
| 105 |
| 106 bool is_more_general_than(const Representation& other) { |
| 107 ASSERT(kind_ != kExternal); |
| 108 ASSERT(other.kind_ != kExternal); |
| 109 return kind_ > other.kind_; |
| 110 } |
| 111 |
| 112 Representation generalize(Representation other) { |
| 113 if (is_more_general_than(other)) { |
| 114 return *this; |
| 115 } else { |
| 116 return other; |
| 117 } |
| 118 } |
| 119 |
| 120 Kind kind() const { return static_cast<Kind>(kind_); } |
| 121 bool IsNone() const { return kind_ == kNone; } |
| 122 bool IsTagged() const { return kind_ == kTagged; } |
| 123 bool IsSmi() const { return kind_ == kSmi; } |
| 124 bool IsInteger32() const { return kind_ == kInteger32; } |
| 125 bool IsDouble() const { return kind_ == kDouble; } |
| 126 bool IsExternal() const { return kind_ == kExternal; } |
| 127 bool IsSpecialization() const { |
| 128 return kind_ == kInteger32 || kind_ == kDouble; |
| 129 } |
| 130 const char* Mnemonic() const; |
| 131 |
| 132 uint8_t DetailsEncoded() { |
| 133 ASSERT(kind_ <= kTagged); |
| 134 if (kind_ < kInteger32) { |
| 135 return kind_; |
| 136 } else { |
| 137 return kind_ - 1; |
| 138 } |
| 139 } |
| 140 |
| 141 static Representation DecodeDetails(uint32_t bits) { |
| 142 ASSERT(bits <= kTagged); |
| 143 if (bits >= kInteger32) bits += 1; |
| 144 return FromKind(static_cast<Kind>(bits)); |
| 145 } |
| 146 |
| 147 private: |
| 148 explicit Representation(Kind k) : kind_(k) { } |
| 149 |
| 150 // Make sure kind fits in int8. |
| 151 STATIC_ASSERT(kNumRepresentations <= (1 << kBitsPerByte)); |
| 152 |
| 153 int8_t kind_; |
| 154 }; |
| 155 |
| 156 |
79 // PropertyDetails captures type and attributes for a property. | 157 // PropertyDetails captures type and attributes for a property. |
80 // They are used both in property dictionaries and instance descriptors. | 158 // They are used both in property dictionaries and instance descriptors. |
81 class PropertyDetails BASE_EMBEDDED { | 159 class PropertyDetails BASE_EMBEDDED { |
82 public: | 160 public: |
83 PropertyDetails(PropertyAttributes attributes, | 161 PropertyDetails(PropertyAttributes attributes, |
84 PropertyType type, | 162 PropertyType type, |
| 163 Representation representation, |
85 int index = 0) { | 164 int index = 0) { |
86 value_ = TypeField::encode(type) | 165 value_ = TypeField::encode(type) |
87 | AttributesField::encode(attributes) | 166 | AttributesField::encode(attributes) |
| 167 | RepresentationField::encode(representation.DetailsEncoded()) |
88 | DictionaryStorageField::encode(index); | 168 | DictionaryStorageField::encode(index); |
89 | 169 |
90 ASSERT(type == this->type()); | 170 ASSERT(type == this->type()); |
91 ASSERT(attributes == this->attributes()); | 171 ASSERT(attributes == this->attributes()); |
92 ASSERT(index == this->dictionary_index()); | 172 if (representation.IsNone()) { |
| 173 ASSERT(index == this->dictionary_index()); |
| 174 } else { |
| 175 ASSERT(index == this->descriptor_index()); |
| 176 } |
93 } | 177 } |
94 | 178 |
95 int pointer() { return DescriptorPointer::decode(value_); } | 179 int pointer() { return DescriptorPointer::decode(value_); } |
96 | 180 |
97 PropertyDetails set_pointer(int i) { return PropertyDetails(value_, i); } | 181 PropertyDetails set_pointer(int i) { return PropertyDetails(value_, i); } |
98 | 182 |
| 183 PropertyDetails set_representation(Representation representation) { |
| 184 return PropertyDetails(value_, representation); |
| 185 } |
| 186 |
99 // Conversion for storing details as Object*. | 187 // Conversion for storing details as Object*. |
100 explicit inline PropertyDetails(Smi* smi); | 188 explicit inline PropertyDetails(Smi* smi); |
101 inline Smi* AsSmi(); | 189 inline Smi* AsSmi(); |
102 | 190 |
103 PropertyType type() { return TypeField::decode(value_); } | 191 PropertyType type() { return TypeField::decode(value_); } |
104 | 192 |
105 PropertyAttributes attributes() const { | 193 PropertyAttributes attributes() const { |
106 return AttributesField::decode(value_); | 194 return AttributesField::decode(value_); |
107 } | 195 } |
108 | 196 |
109 int dictionary_index() { | 197 int dictionary_index() { |
110 return DictionaryStorageField::decode(value_); | 198 return DictionaryStorageField::decode(value_); |
111 } | 199 } |
112 | 200 |
113 int descriptor_index() { | 201 int descriptor_index() { |
114 return DescriptorStorageField::decode(value_); | 202 return DescriptorStorageField::decode(value_); |
115 } | 203 } |
116 | 204 |
| 205 Representation representation() { |
| 206 return Representation::DecodeDetails(RepresentationField::decode(value_)); |
| 207 } |
| 208 |
117 inline PropertyDetails AsDeleted(); | 209 inline PropertyDetails AsDeleted(); |
118 | 210 |
119 static bool IsValidIndex(int index) { | 211 static bool IsValidIndex(int index) { |
120 return DictionaryStorageField::is_valid(index); | 212 return DictionaryStorageField::is_valid(index); |
121 } | 213 } |
122 | 214 |
123 bool IsReadOnly() const { return (attributes() & READ_ONLY) != 0; } | 215 bool IsReadOnly() const { return (attributes() & READ_ONLY) != 0; } |
124 bool IsDontDelete() const { return (attributes() & DONT_DELETE) != 0; } | 216 bool IsDontDelete() const { return (attributes() & DONT_DELETE) != 0; } |
125 bool IsDontEnum() const { return (attributes() & DONT_ENUM) != 0; } | 217 bool IsDontEnum() const { return (attributes() & DONT_ENUM) != 0; } |
126 bool IsDeleted() const { return DeletedField::decode(value_) != 0;} | 218 bool IsDeleted() const { return DeletedField::decode(value_) != 0;} |
127 | 219 |
128 // Bit fields in value_ (type, shift, size). Must be public so the | 220 // Bit fields in value_ (type, shift, size). Must be public so the |
129 // constants can be embedded in generated code. | 221 // constants can be embedded in generated code. |
130 class TypeField: public BitField<PropertyType, 0, 3> {}; | 222 class TypeField: public BitField<PropertyType, 0, 3> {}; |
131 class AttributesField: public BitField<PropertyAttributes, 3, 3> {}; | 223 class AttributesField: public BitField<PropertyAttributes, 3, 3> {}; |
132 class DeletedField: public BitField<uint32_t, 6, 1> {}; | 224 class DeletedField: public BitField<uint32_t, 6, 1> {}; |
133 class DictionaryStorageField: public BitField<uint32_t, 7, 24> {}; | 225 class DictionaryStorageField: public BitField<uint32_t, 7, 24> {}; |
134 class DescriptorStorageField: public BitField<uint32_t, 7, 11> {}; | 226 class DescriptorStorageField: public BitField<uint32_t, 7, 11> {}; |
135 class DescriptorPointer: public BitField<uint32_t, 18, 11> {}; | 227 class DescriptorPointer: public BitField<uint32_t, 18, 11> {}; |
| 228 class RepresentationField: public BitField<uint32_t, 29, 2> {}; |
136 | 229 |
137 static const int kInitialIndex = 1; | 230 static const int kInitialIndex = 1; |
138 | 231 |
139 private: | 232 private: |
140 PropertyDetails(int value, int pointer) { | 233 PropertyDetails(int value, int pointer) { |
141 value_ = DescriptorPointer::update(value, pointer); | 234 value_ = DescriptorPointer::update(value, pointer); |
| 235 } |
| 236 PropertyDetails(int value, Representation representation) { |
| 237 value_ = RepresentationField::update( |
| 238 value, representation.DetailsEncoded()); |
142 } | 239 } |
143 | 240 |
144 uint32_t value_; | 241 uint32_t value_; |
145 }; | 242 }; |
146 | 243 |
147 } } // namespace v8::internal | 244 } } // namespace v8::internal |
148 | 245 |
149 #endif // V8_PROPERTY_DETAILS_H_ | 246 #endif // V8_PROPERTY_DETAILS_H_ |
OLD | NEW |