| OLD | NEW |
| (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_LAYOUT_DESCRIPTOR_H_ | |
| 6 #define V8_LAYOUT_DESCRIPTOR_H_ | |
| 7 | |
| 8 #include <iosfwd> | |
| 9 | |
| 10 #include "src/objects.h" | |
| 11 | |
| 12 namespace v8 { | |
| 13 namespace internal { | |
| 14 | |
| 15 // LayoutDescriptor is a bit vector defining which fields contain non-tagged | |
| 16 // values. It could either be a fixed typed array (slow form) or a Smi | |
| 17 // if the length fits (fast form). | |
| 18 // Each bit in the layout represents a FIELD. The bits are referenced by | |
| 19 // field_index which is a field number. If the bit is set then the corresponding | |
| 20 // field contains a non-tagged value and therefore must be skipped by GC. | |
| 21 // Otherwise the field is considered tagged. If the queried bit lays "outside" | |
| 22 // of the descriptor then the field is also considered tagged. | |
| 23 // Once a layout descriptor is created it is allowed only to append properties | |
| 24 // to it. | |
| 25 class LayoutDescriptor : public FixedTypedArray<Uint32ArrayTraits> { | |
| 26 public: | |
| 27 V8_INLINE bool IsTagged(int field_index); | |
| 28 | |
| 29 // Returns true if this is a layout of the object having only tagged fields. | |
| 30 V8_INLINE bool IsFastPointerLayout(); | |
| 31 | |
| 32 // Returns true if the layout descriptor is in non-Smi form. | |
| 33 V8_INLINE bool IsSlowLayout(); | |
| 34 | |
| 35 V8_INLINE static LayoutDescriptor* cast(Object* object); | |
| 36 V8_INLINE static const LayoutDescriptor* cast(const Object* object); | |
| 37 | |
| 38 V8_INLINE static LayoutDescriptor* cast_gc_safe(Object* object); | |
| 39 | |
| 40 // Builds layout descriptor optimized for given |map| by |num_descriptors| | |
| 41 // elements of given descriptors array. The |map|'s descriptors could be | |
| 42 // different. | |
| 43 static Handle<LayoutDescriptor> New(Handle<Map> map, | |
| 44 Handle<DescriptorArray> descriptors, | |
| 45 int num_descriptors); | |
| 46 | |
| 47 // Creates new layout descriptor by appending property with |details| to | |
| 48 // |map|'s layout descriptor. | |
| 49 static Handle<LayoutDescriptor> Append(Handle<Map> map, | |
| 50 PropertyDetails details); | |
| 51 | |
| 52 // Creates new layout descriptor by appending property with |details| to | |
| 53 // |map|'s layout descriptor and if it is still fast then returns it. | |
| 54 // Otherwise the |full_layout_descriptor| is returned. | |
| 55 static Handle<LayoutDescriptor> AppendIfFastOrUseFull( | |
| 56 Handle<Map> map, PropertyDetails details, | |
| 57 Handle<LayoutDescriptor> full_layout_descriptor); | |
| 58 | |
| 59 // Layout descriptor that corresponds to an object all fields of which are | |
| 60 // tagged (FastPointerLayout). | |
| 61 V8_INLINE static LayoutDescriptor* FastPointerLayout(); | |
| 62 | |
| 63 #ifdef DEBUG | |
| 64 // Check that this layout descriptor corresponds to given map. | |
| 65 bool IsConsistentWithMap(Map* map); | |
| 66 #endif | |
| 67 | |
| 68 #ifdef OBJECT_PRINT | |
| 69 // For our gdb macros, we should perhaps change these in the future. | |
| 70 void Print(); | |
| 71 | |
| 72 void Print(std::ostream& os); // NOLINT | |
| 73 #endif | |
| 74 | |
| 75 // Capacity of layout descriptors in bits. | |
| 76 V8_INLINE int capacity(); | |
| 77 | |
| 78 V8_INLINE LayoutDescriptor* SetTaggedForTesting(int field_index, | |
| 79 bool tagged) { | |
| 80 return SetTagged(field_index, tagged); | |
| 81 } | |
| 82 | |
| 83 private: | |
| 84 static const int kNumberOfBits = 32; | |
| 85 | |
| 86 V8_INLINE static Handle<LayoutDescriptor> New(Isolate* isolate, int length); | |
| 87 V8_INLINE static LayoutDescriptor* FromSmi(Smi* smi); | |
| 88 | |
| 89 V8_INLINE static bool InobjectUnboxedField(int inobject_properties, | |
| 90 PropertyDetails details); | |
| 91 | |
| 92 static Handle<LayoutDescriptor> EnsureCapacity( | |
| 93 Isolate* isolate, Handle<LayoutDescriptor> layout_descriptor, | |
| 94 int new_capacity); | |
| 95 | |
| 96 // Returns false if requested field_index is out of bounds. | |
| 97 V8_INLINE bool GetIndexes(int field_index, int* layout_word_index, | |
| 98 uint32_t* layout_mask); | |
| 99 | |
| 100 V8_INLINE MUST_USE_RESULT LayoutDescriptor* SetRawData(int field_index) { | |
| 101 return SetTagged(field_index, false); | |
| 102 } | |
| 103 | |
| 104 V8_INLINE MUST_USE_RESULT LayoutDescriptor* SetTagged(int field_index, | |
| 105 bool tagged); | |
| 106 }; | |
| 107 | |
| 108 | |
| 109 // InobjectPropertiesHelper is a helper class for querying layout descriptor | |
| 110 // about whether the field at given offset is tagged or not. | |
| 111 class InobjectPropertiesHelper { | |
| 112 public: | |
| 113 inline explicit InobjectPropertiesHelper(Map* map); | |
| 114 | |
| 115 bool all_fields_tagged() { return all_fields_tagged_; } | |
| 116 inline bool IsTagged(int offset_in_bytes); | |
| 117 | |
| 118 private: | |
| 119 bool all_fields_tagged_; | |
| 120 int header_size_; | |
| 121 LayoutDescriptor* layout_descriptor_; | |
| 122 }; | |
| 123 } | |
| 124 } // namespace v8::internal | |
| 125 | |
| 126 #endif // V8_LAYOUT_DESCRIPTOR_H_ | |
| OLD | NEW |