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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 TRANSITION = 6, | 75 TRANSITION = 6, |
76 // Only used as a marker in LookupResult. | 76 // Only used as a marker in LookupResult. |
77 NONEXISTENT = 7 | 77 NONEXISTENT = 7 |
78 }; | 78 }; |
79 | 79 |
80 | 80 |
81 class Representation { | 81 class Representation { |
82 public: | 82 public: |
83 enum Kind { | 83 enum Kind { |
84 kNone, | 84 kNone, |
85 kInteger8, | 85 kByte, |
86 kUInteger8, | |
87 kInteger16, | |
88 kUInteger16, | |
89 kSmi, | 86 kSmi, |
90 kInteger32, | 87 kInteger32, |
91 kDouble, | 88 kDouble, |
92 kHeapObject, | 89 kHeapObject, |
93 kTagged, | 90 kTagged, |
94 kExternal, | 91 kExternal, |
95 kNumRepresentations | 92 kNumRepresentations |
96 }; | 93 }; |
97 | 94 |
98 Representation() : kind_(kNone) { } | 95 Representation() : kind_(kNone) { } |
99 | 96 |
100 static Representation None() { return Representation(kNone); } | 97 static Representation None() { return Representation(kNone); } |
101 static Representation Tagged() { return Representation(kTagged); } | 98 static Representation Tagged() { return Representation(kTagged); } |
102 static Representation Integer8() { return Representation(kInteger8); } | 99 static Representation Byte() { return Representation(kByte); } |
103 static Representation UInteger8() { return Representation(kUInteger8); } | |
104 static Representation Integer16() { return Representation(kInteger16); } | |
105 static Representation UInteger16() { | |
106 return Representation(kUInteger16); | |
107 } | |
108 static Representation Smi() { return Representation(kSmi); } | 100 static Representation Smi() { return Representation(kSmi); } |
109 static Representation Integer32() { return Representation(kInteger32); } | 101 static Representation Integer32() { return Representation(kInteger32); } |
110 static Representation Double() { return Representation(kDouble); } | 102 static Representation Double() { return Representation(kDouble); } |
111 static Representation HeapObject() { return Representation(kHeapObject); } | 103 static Representation HeapObject() { return Representation(kHeapObject); } |
112 static Representation External() { return Representation(kExternal); } | 104 static Representation External() { return Representation(kExternal); } |
113 | 105 |
114 static Representation FromKind(Kind kind) { return Representation(kind); } | 106 static Representation FromKind(Kind kind) { return Representation(kind); } |
115 | 107 |
116 // TODO(rossberg): this should die eventually. | 108 // TODO(rossberg): this should die eventually. |
117 static Representation FromType(TypeInfo info); | 109 static Representation FromType(TypeInfo info); |
118 static Representation FromType(Handle<Type> type); | 110 static Representation FromType(Handle<Type> type); |
119 | 111 |
120 bool Equals(const Representation& other) const { | 112 bool Equals(const Representation& other) const { |
121 return kind_ == other.kind_; | 113 return kind_ == other.kind_; |
122 } | 114 } |
123 | 115 |
124 bool IsCompatibleForLoad(const Representation& other) const { | 116 bool IsCompatibleForLoad(const Representation& other) const { |
125 return (IsDouble() && other.IsDouble()) || | 117 return (IsDouble() && other.IsDouble()) || |
126 (!IsDouble() && !other.IsDouble()); | 118 (!IsDouble() && !other.IsDouble()); |
127 } | 119 } |
128 | 120 |
129 bool IsCompatibleForStore(const Representation& other) const { | 121 bool IsCompatibleForStore(const Representation& other) const { |
130 return Equals(other); | 122 return Equals(other); |
131 } | 123 } |
132 | 124 |
133 bool is_more_general_than(const Representation& other) const { | 125 bool is_more_general_than(const Representation& other) const { |
134 ASSERT(kind_ != kExternal); | 126 ASSERT(kind_ != kExternal); |
135 ASSERT(other.kind_ != kExternal); | 127 ASSERT(other.kind_ != kExternal); |
136 if (IsHeapObject()) return other.IsDouble() || other.IsNone(); | 128 if (IsHeapObject()) return other.IsDouble() || other.IsNone(); |
137 if (kind_ == kUInteger8 && other.kind_ == kInteger8) return false; | |
138 if (kind_ == kUInteger16 && other.kind_ == kInteger16) return false; | |
139 return kind_ > other.kind_; | 129 return kind_ > other.kind_; |
140 } | 130 } |
141 | 131 |
142 bool fits_into(const Representation& other) const { | 132 bool fits_into(const Representation& other) const { |
143 return other.is_more_general_than(*this) || other.Equals(*this); | 133 return other.is_more_general_than(*this) || other.Equals(*this); |
144 } | 134 } |
145 | 135 |
146 Representation generalize(Representation other) { | 136 Representation generalize(Representation other) { |
147 if (other.fits_into(*this)) return *this; | 137 if (other.fits_into(*this)) return *this; |
148 if (other.is_more_general_than(*this)) return other; | 138 if (other.is_more_general_than(*this)) return other; |
149 return Representation::Tagged(); | 139 return Representation::Tagged(); |
150 } | 140 } |
151 | 141 |
152 int size() const { | |
153 ASSERT(!IsNone()); | |
154 if (IsInteger8() || IsUInteger8()) { | |
155 return sizeof(uint8_t); | |
156 } | |
157 if (IsInteger16() || IsUInteger16()) { | |
158 return sizeof(uint16_t); | |
159 } | |
160 if (IsInteger32()) { | |
161 return sizeof(uint32_t); | |
162 } | |
163 return kPointerSize; | |
164 } | |
165 | |
166 Kind kind() const { return static_cast<Kind>(kind_); } | 142 Kind kind() const { return static_cast<Kind>(kind_); } |
167 bool IsNone() const { return kind_ == kNone; } | 143 bool IsNone() const { return kind_ == kNone; } |
168 bool IsInteger8() const { return kind_ == kInteger8; } | 144 bool IsByte() const { return kind_ == kByte; } |
169 bool IsUInteger8() const { return kind_ == kUInteger8; } | |
170 bool IsInteger16() const { return kind_ == kInteger16; } | |
171 bool IsUInteger16() const { return kind_ == kUInteger16; } | |
172 bool IsTagged() const { return kind_ == kTagged; } | 145 bool IsTagged() const { return kind_ == kTagged; } |
173 bool IsSmi() const { return kind_ == kSmi; } | 146 bool IsSmi() const { return kind_ == kSmi; } |
174 bool IsSmiOrTagged() const { return IsSmi() || IsTagged(); } | 147 bool IsSmiOrTagged() const { return IsSmi() || IsTagged(); } |
175 bool IsInteger32() const { return kind_ == kInteger32; } | 148 bool IsInteger32() const { return kind_ == kInteger32; } |
176 bool IsSmiOrInteger32() const { return IsSmi() || IsInteger32(); } | 149 bool IsSmiOrInteger32() const { return IsSmi() || IsInteger32(); } |
177 bool IsDouble() const { return kind_ == kDouble; } | 150 bool IsDouble() const { return kind_ == kDouble; } |
178 bool IsHeapObject() const { return kind_ == kHeapObject; } | 151 bool IsHeapObject() const { return kind_ == kHeapObject; } |
179 bool IsExternal() const { return kind_ == kExternal; } | 152 bool IsExternal() const { return kind_ == kExternal; } |
180 bool IsSpecialization() const { | 153 bool IsSpecialization() const { |
181 return IsInteger8() || IsUInteger8() || | 154 return IsByte() || IsSmi() || IsInteger32() || IsDouble(); |
182 IsInteger16() || IsUInteger16() || | |
183 IsSmi() || IsInteger32() || IsDouble(); | |
184 } | 155 } |
185 const char* Mnemonic() const; | 156 const char* Mnemonic() const; |
186 | 157 |
187 private: | 158 private: |
188 explicit Representation(Kind k) : kind_(k) { } | 159 explicit Representation(Kind k) : kind_(k) { } |
189 | 160 |
190 // Make sure kind fits in int8. | 161 // Make sure kind fits in int8. |
191 STATIC_ASSERT(kNumRepresentations <= (1 << kBitsPerByte)); | 162 STATIC_ASSERT(kNumRepresentations <= (1 << kBitsPerByte)); |
192 | 163 |
193 int8_t kind_; | 164 int8_t kind_; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 // constants can be embedded in generated code. | 249 // constants can be embedded in generated code. |
279 class TypeField: public BitField<PropertyType, 0, 3> {}; | 250 class TypeField: public BitField<PropertyType, 0, 3> {}; |
280 class AttributesField: public BitField<PropertyAttributes, 3, 3> {}; | 251 class AttributesField: public BitField<PropertyAttributes, 3, 3> {}; |
281 | 252 |
282 // Bit fields for normalized objects. | 253 // Bit fields for normalized objects. |
283 class DeletedField: public BitField<uint32_t, 6, 1> {}; | 254 class DeletedField: public BitField<uint32_t, 6, 1> {}; |
284 class DictionaryStorageField: public BitField<uint32_t, 7, 24> {}; | 255 class DictionaryStorageField: public BitField<uint32_t, 7, 24> {}; |
285 | 256 |
286 // Bit fields for fast objects. | 257 // Bit fields for fast objects. |
287 class DescriptorPointer: public BitField<uint32_t, 6, 11> {}; | 258 class DescriptorPointer: public BitField<uint32_t, 6, 11> {}; |
288 class RepresentationField: public BitField<uint32_t, 17, 4> {}; | 259 class RepresentationField: public BitField<uint32_t, 17, 3> {}; |
289 class FieldIndexField: public BitField<uint32_t, 21, 10> {}; | 260 class FieldIndexField: public BitField<uint32_t, 20, 11> {}; |
290 | 261 |
291 static const int kInitialIndex = 1; | 262 static const int kInitialIndex = 1; |
292 | 263 |
293 private: | 264 private: |
294 PropertyDetails(int value, int pointer) { | 265 PropertyDetails(int value, int pointer) { |
295 value_ = DescriptorPointer::update(value, pointer); | 266 value_ = DescriptorPointer::update(value, pointer); |
296 } | 267 } |
297 PropertyDetails(int value, Representation representation) { | 268 PropertyDetails(int value, Representation representation) { |
298 value_ = RepresentationField::update( | 269 value_ = RepresentationField::update( |
299 value, EncodeRepresentation(representation)); | 270 value, EncodeRepresentation(representation)); |
300 } | 271 } |
301 PropertyDetails(int value, PropertyAttributes attributes) { | 272 PropertyDetails(int value, PropertyAttributes attributes) { |
302 value_ = AttributesField::update(value, attributes); | 273 value_ = AttributesField::update(value, attributes); |
303 } | 274 } |
304 | 275 |
305 uint32_t value_; | 276 uint32_t value_; |
306 }; | 277 }; |
307 | 278 |
308 } } // namespace v8::internal | 279 } } // namespace v8::internal |
309 | 280 |
310 #endif // V8_PROPERTY_DETAILS_H_ | 281 #endif // V8_PROPERTY_DETAILS_H_ |
OLD | NEW |