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.
5 #ifndef V8_LAYOUT_DESCRIPTOR_H_
6 #define V8_LAYOUT_DESCRIPTOR_H_
10 #include "src/objects.h"
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
25 class LayoutDescriptor : public FixedTypedArray<Uint32ArrayTraits> {
27 V8_INLINE bool IsTagged(int field_index);
29 // Returns true if this is a layout of the object having only tagged fields.
30 V8_INLINE bool IsFastPointerLayout();
31 V8_INLINE static bool IsFastPointerLayout(Object* layout_descriptor);
33 // Returns true if the layout descriptor is in non-Smi form.
34 V8_INLINE bool IsSlowLayout();
36 V8_INLINE static LayoutDescriptor* cast(Object* object);
37 V8_INLINE static const LayoutDescriptor* cast(const Object* object);
39 V8_INLINE static LayoutDescriptor* cast_gc_safe(Object* object);
41 // Builds layout descriptor optimized for given |map| by |num_descriptors|
42 // elements of given descriptors array. The |map|'s descriptors could be
44 static Handle<LayoutDescriptor> New(Handle<Map> map,
45 Handle<DescriptorArray> descriptors,
48 // Creates new layout descriptor by appending property with |details| to
49 // |map|'s layout descriptor.
50 static Handle<LayoutDescriptor> Append(Handle<Map> map,
51 PropertyDetails details);
53 // Creates new layout descriptor by appending property with |details| to
54 // |map|'s layout descriptor and if it is still fast then returns it.
55 // Otherwise the |full_layout_descriptor| is returned.
56 static Handle<LayoutDescriptor> AppendIfFastOrUseFull(
57 Handle<Map> map, PropertyDetails details,
58 Handle<LayoutDescriptor> full_layout_descriptor);
60 // Layout descriptor that corresponds to an object all fields of which are
61 // tagged (FastPointerLayout).
62 V8_INLINE static LayoutDescriptor* FastPointerLayout();
65 // Check that this layout descriptor corresponds to given map.
66 bool IsConsistentWithMap(Map* map);
70 // For our gdb macros, we should perhaps change these in the future.
73 void Print(std::ostream& os); // NOLINT
76 // Capacity of layout descriptors in bits.
77 V8_INLINE int capacity();
79 V8_INLINE LayoutDescriptor* SetTaggedForTesting(int field_index,
81 return SetTagged(field_index, tagged);
85 static const int kNumberOfBits = 32;
87 V8_INLINE static Handle<LayoutDescriptor> New(Isolate* isolate, int length);
88 V8_INLINE static LayoutDescriptor* FromSmi(Smi* smi);
90 V8_INLINE static bool InobjectUnboxedField(int inobject_properties,
91 PropertyDetails details);
93 static Handle<LayoutDescriptor> EnsureCapacity(
94 Isolate* isolate, Handle<LayoutDescriptor> layout_descriptor,
97 // Returns false if requested field_index is out of bounds.
98 V8_INLINE bool GetIndexes(int field_index, int* layout_word_index,
99 uint32_t* layout_mask);
101 V8_INLINE MUST_USE_RESULT LayoutDescriptor* SetRawData(int field_index) {
102 return SetTagged(field_index, false);
105 V8_INLINE MUST_USE_RESULT LayoutDescriptor* SetTagged(int field_index,
110 // InobjectPropertiesHelper is a helper class for querying layout descriptor
111 // about whether the field at given offset is tagged or not.
112 class InobjectPropertiesHelper {
114 inline explicit InobjectPropertiesHelper(Map* map);
116 bool all_fields_tagged() { return all_fields_tagged_; }
117 inline bool IsTagged(int offset_in_bytes);
120 bool all_fields_tagged_;
122 LayoutDescriptor* layout_descriptor_;
125 } // namespace v8::internal
127 #endif // V8_LAYOUT_DESCRIPTOR_H_