OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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_PROPERTY_DETAILS_H_ | 5 #ifndef V8_PROPERTY_DETAILS_H_ |
6 #define V8_PROPERTY_DETAILS_H_ | 6 #define V8_PROPERTY_DETAILS_H_ |
7 | 7 |
8 #include "include/v8.h" | 8 #include "include/v8.h" |
9 #include "src/allocation.h" | 9 #include "src/allocation.h" |
10 #include "src/utils.h" | 10 #include "src/utils.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 class TypeInfo; | 65 class TypeInfo; |
66 | 66 |
67 // Order of kinds is significant. | 67 // Order of kinds is significant. |
68 // Must fit in the BitField PropertyDetails::KindField. | 68 // Must fit in the BitField PropertyDetails::KindField. |
69 enum PropertyKind { kData = 0, kAccessor = 1 }; | 69 enum PropertyKind { kData = 0, kAccessor = 1 }; |
70 | 70 |
71 // Order of modes is significant. | 71 // Order of modes is significant. |
72 // Must fit in the BitField PropertyDetails::LocationField. | 72 // Must fit in the BitField PropertyDetails::LocationField. |
73 enum PropertyLocation { kField = 0, kDescriptor = 1 }; | 73 enum PropertyLocation { kField = 0, kDescriptor = 1 }; |
74 | 74 |
75 // Order of modes is significant. | |
76 // Must fit in the BitField PropertyDetails::ConstnessField. | |
77 enum PropertyConstness { kMutable = 0, kConst = 1 }; | |
78 | |
75 class Representation { | 79 class Representation { |
76 public: | 80 public: |
77 enum Kind { | 81 enum Kind { |
78 kNone, | 82 kNone, |
79 kInteger8, | 83 kInteger8, |
80 kUInteger8, | 84 kUInteger8, |
81 kInteger16, | 85 kInteger16, |
82 kUInteger16, | 86 kUInteger16, |
83 kSmi, | 87 kSmi, |
84 kInteger32, | 88 kInteger32, |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
224 PropertyDetails(PropertyKind kind, PropertyAttributes attributes, int index, | 228 PropertyDetails(PropertyKind kind, PropertyAttributes attributes, int index, |
225 PropertyCellType cell_type) { | 229 PropertyCellType cell_type) { |
226 value_ = KindField::encode(kind) | LocationField::encode(kField) | | 230 value_ = KindField::encode(kind) | LocationField::encode(kField) | |
227 AttributesField::encode(attributes) | | 231 AttributesField::encode(attributes) | |
228 DictionaryStorageField::encode(index) | | 232 DictionaryStorageField::encode(index) | |
229 PropertyCellTypeField::encode(cell_type); | 233 PropertyCellTypeField::encode(cell_type); |
230 } | 234 } |
231 | 235 |
232 // Property details for fast mode properties. | 236 // Property details for fast mode properties. |
233 PropertyDetails(PropertyKind kind, PropertyAttributes attributes, | 237 PropertyDetails(PropertyKind kind, PropertyAttributes attributes, |
234 PropertyLocation location, Representation representation, | 238 PropertyLocation location, PropertyConstness constness, |
235 int field_index = 0) { | 239 Representation representation, int field_index = 0) { |
236 value_ = KindField::encode(kind) | LocationField::encode(location) | | 240 value_ = KindField::encode(kind) | AttributesField::encode(attributes) | |
237 AttributesField::encode(attributes) | | 241 LocationField::encode(location) | |
242 ConstnessField::encode(constness) | | |
238 RepresentationField::encode(EncodeRepresentation(representation)) | | 243 RepresentationField::encode(EncodeRepresentation(representation)) | |
239 FieldIndexField::encode(field_index); | 244 FieldIndexField::encode(field_index); |
240 } | 245 } |
241 | 246 |
242 static PropertyDetails Empty( | 247 static PropertyDetails Empty( |
243 PropertyCellType cell_type = PropertyCellType::kNoCell) { | 248 PropertyCellType cell_type = PropertyCellType::kNoCell) { |
244 return PropertyDetails(kData, NONE, 0, cell_type); | 249 return PropertyDetails(kData, NONE, 0, cell_type); |
245 } | 250 } |
246 | 251 |
247 int pointer() const { return DescriptorPointer::decode(value_); } | 252 int pointer() const { return DescriptorPointer::decode(value_); } |
(...skipping 30 matching lines...) Expand all Loading... | |
278 static uint8_t EncodeRepresentation(Representation representation) { | 283 static uint8_t EncodeRepresentation(Representation representation) { |
279 return representation.kind(); | 284 return representation.kind(); |
280 } | 285 } |
281 | 286 |
282 static Representation DecodeRepresentation(uint32_t bits) { | 287 static Representation DecodeRepresentation(uint32_t bits) { |
283 return Representation::FromKind(static_cast<Representation::Kind>(bits)); | 288 return Representation::FromKind(static_cast<Representation::Kind>(bits)); |
284 } | 289 } |
285 | 290 |
286 PropertyKind kind() const { return KindField::decode(value_); } | 291 PropertyKind kind() const { return KindField::decode(value_); } |
287 PropertyLocation location() const { return LocationField::decode(value_); } | 292 PropertyLocation location() const { return LocationField::decode(value_); } |
293 PropertyConstness constness() const { return ConstnessField::decode(value_); } | |
288 | 294 |
289 PropertyAttributes attributes() const { | 295 PropertyAttributes attributes() const { |
290 return AttributesField::decode(value_); | 296 return AttributesField::decode(value_); |
291 } | 297 } |
292 | 298 |
293 int dictionary_index() const { | 299 int dictionary_index() const { |
294 return DictionaryStorageField::decode(value_); | 300 return DictionaryStorageField::decode(value_); |
295 } | 301 } |
296 | 302 |
297 Representation representation() const { | 303 Representation representation() const { |
(...skipping 12 matching lines...) Expand all Loading... | |
310 bool IsConfigurable() const { return (attributes() & DONT_DELETE) == 0; } | 316 bool IsConfigurable() const { return (attributes() & DONT_DELETE) == 0; } |
311 bool IsDontEnum() const { return (attributes() & DONT_ENUM) != 0; } | 317 bool IsDontEnum() const { return (attributes() & DONT_ENUM) != 0; } |
312 bool IsEnumerable() const { return !IsDontEnum(); } | 318 bool IsEnumerable() const { return !IsDontEnum(); } |
313 PropertyCellType cell_type() const { | 319 PropertyCellType cell_type() const { |
314 return PropertyCellTypeField::decode(value_); | 320 return PropertyCellTypeField::decode(value_); |
315 } | 321 } |
316 | 322 |
317 // Bit fields in value_ (type, shift, size). Must be public so the | 323 // Bit fields in value_ (type, shift, size). Must be public so the |
318 // constants can be embedded in generated code. | 324 // constants can be embedded in generated code. |
319 class KindField : public BitField<PropertyKind, 0, 1> {}; | 325 class KindField : public BitField<PropertyKind, 0, 1> {}; |
320 class LocationField : public BitField<PropertyLocation, 1, 1> {}; | 326 class LocationField : public BitField<PropertyLocation, KindField::kNext, 1> { |
321 class AttributesField : public BitField<PropertyAttributes, 2, 3> {}; | 327 }; |
328 class ConstnessField | |
329 : public BitField<PropertyConstness, LocationField::kNext, 1> {}; | |
330 class AttributesField | |
331 : public BitField<PropertyAttributes, ConstnessField::kNext, 3> {}; | |
322 static const int kAttributesReadOnlyMask = | 332 static const int kAttributesReadOnlyMask = |
323 (READ_ONLY << AttributesField::kShift); | 333 (READ_ONLY << AttributesField::kShift); |
324 | 334 |
325 // Bit fields for normalized objects. | 335 // Bit fields for normalized objects. |
326 class PropertyCellTypeField : public BitField<PropertyCellType, 5, 2> {}; | 336 class PropertyCellTypeField |
327 class DictionaryStorageField : public BitField<uint32_t, 7, 24> {}; | 337 : public BitField<PropertyCellType, AttributesField::kNext, 2> {}; |
338 class DictionaryStorageField | |
339 : public BitField<uint32_t, PropertyCellTypeField::kNext, 23> {}; | |
328 | 340 |
329 // Bit fields for fast objects. | 341 // Bit fields for fast objects. |
330 class RepresentationField : public BitField<uint32_t, 5, 4> {}; | 342 class RepresentationField |
343 : public BitField<uint32_t, AttributesField::kNext, 4> {}; | |
331 class DescriptorPointer | 344 class DescriptorPointer |
332 : public BitField<uint32_t, 9, kDescriptorIndexBitCount> {}; // NOLINT | 345 : public BitField<uint32_t, RepresentationField::kNext, |
333 class FieldIndexField | |
334 : public BitField<uint32_t, 9 + kDescriptorIndexBitCount, | |
335 kDescriptorIndexBitCount> {}; // NOLINT | 346 kDescriptorIndexBitCount> {}; // NOLINT |
347 class FieldIndexField : public BitField<uint32_t, DescriptorPointer::kNext, | |
348 kDescriptorIndexBitCount> { | |
349 }; // NOLINT | |
336 | 350 |
337 // All bits for both fast and slow objects must fit in a smi. | 351 // All bits for both fast and slow objects must fit in a smi. |
338 STATIC_ASSERT(DictionaryStorageField::kNext <= 31); | 352 STATIC_ASSERT(DictionaryStorageField::kNext <= 31); |
339 STATIC_ASSERT(FieldIndexField::kNext <= 31); | 353 STATIC_ASSERT(FieldIndexField::kNext <= 31); |
340 | 354 |
341 static const int kInitialIndex = 1; | 355 static const int kInitialIndex = 1; |
342 | 356 |
343 #ifdef OBJECT_PRINT | 357 #ifdef OBJECT_PRINT |
344 // For our gdb macros, we should perhaps change these in the future. | 358 // For our gdb macros, we should perhaps change these in the future. |
345 void Print(bool dictionary_mode); | 359 void Print(bool dictionary_mode); |
(...skipping 20 matching lines...) Expand all Loading... | |
366 value_ = RepresentationField::update( | 380 value_ = RepresentationField::update( |
367 value, EncodeRepresentation(representation)); | 381 value, EncodeRepresentation(representation)); |
368 } | 382 } |
369 PropertyDetails(int value, PropertyAttributes attributes) { | 383 PropertyDetails(int value, PropertyAttributes attributes) { |
370 value_ = AttributesField::update(value, attributes); | 384 value_ = AttributesField::update(value, attributes); |
371 } | 385 } |
372 | 386 |
373 uint32_t value_; | 387 uint32_t value_; |
374 }; | 388 }; |
375 | 389 |
390 inline bool LocationFitsInto(PropertyLocation what, PropertyLocation where) { | |
Toon Verwaest
2017/01/18 12:04:05
Maybe LocationIsMoreGeneralThan? That fits the Gen
Igor Sheludko
2017/01/18 14:06:43
Done.
| |
391 return where == kField || what == kDescriptor; | |
Toon Verwaest
2017/01/18 12:04:05
// Everything fits in a field, and a descriptor on
Igor Sheludko
2017/01/18 14:06:43
Done.
| |
392 } | |
393 | |
394 inline bool ConstnessFitsInto(PropertyConstness what, PropertyConstness where) { | |
395 return where == kMutable || what == kConst; | |
396 } | |
397 | |
398 inline PropertyConstness GeneralizeConstness(PropertyConstness c1, | |
399 PropertyConstness c2) { | |
400 return c1 == kMutable ? kMutable : c2; | |
401 } | |
376 | 402 |
377 std::ostream& operator<<(std::ostream& os, | 403 std::ostream& operator<<(std::ostream& os, |
378 const PropertyAttributes& attributes); | 404 const PropertyAttributes& attributes); |
379 } // namespace internal | 405 } // namespace internal |
380 } // namespace v8 | 406 } // namespace v8 |
381 | 407 |
382 #endif // V8_PROPERTY_DETAILS_H_ | 408 #endif // V8_PROPERTY_DETAILS_H_ |
OLD | NEW |