• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 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_OBJECTS_PROPERTY_ARRAY_H_
6 #define V8_OBJECTS_PROPERTY_ARRAY_H_
7 
8 #include "src/objects/heap-object.h"
9 
10 // Has to be the last include (doesn't have include guards):
11 #include "src/objects/object-macros.h"
12 
13 namespace v8 {
14 namespace internal {
15 
16 #include "torque-generated/src/objects/property-array-tq.inc"
17 
18 class PropertyArray
19     : public TorqueGeneratedPropertyArray<PropertyArray, HeapObject> {
20  public:
21   // [length]: length of the array.
22   inline int length() const;
23   inline int length(AcquireLoadTag) const;
24 
25   // This is only used on a newly allocated PropertyArray which
26   // doesn't have an existing hash.
27   inline void initialize_length(int length);
28 
29   inline void SetHash(int hash);
30   inline int Hash() const;
31 
32   inline Object get(int index) const;
33   inline Object get(PtrComprCageBase cage_base, int index) const;
34   inline Object get(int index, SeqCstAccessTag tag) const;
35   inline Object get(PtrComprCageBase cage_base, int index,
36                     SeqCstAccessTag tag) const;
37 
38   inline void set(int index, Object value);
39   inline void set(int index, Object value, SeqCstAccessTag tag);
40   // Setter with explicit barrier mode.
41   inline void set(int index, Object value, WriteBarrierMode mode);
42 
43   inline Object Swap(int index, Object value, SeqCstAccessTag tag);
44   inline Object Swap(PtrComprCageBase cage_base, int index, Object value,
45                      SeqCstAccessTag tag);
46 
47   // Signature must be in sync with FixedArray::CopyElements().
48   inline void CopyElements(Isolate* isolate, int dst_index, PropertyArray src,
49                            int src_index, int len, WriteBarrierMode mode);
50 
51   // Gives access to raw memory which stores the array's data.
52   inline ObjectSlot data_start();
53 
54   // Garbage collection support.
SizeFor(int length)55   static constexpr int SizeFor(int length) {
56     return kHeaderSize + length * kTaggedSize;
57   }
OffsetOfElementAt(int index)58   static constexpr int OffsetOfElementAt(int index) { return SizeFor(index); }
59 
60   DECL_PRINTER(PropertyArray)
61   DECL_VERIFIER(PropertyArray)
62 
63   // Garbage collection support.
64   using BodyDescriptor = FlexibleBodyDescriptor<kHeaderSize>;
65 
66   static const int kLengthFieldSize = 10;
67   using LengthField = base::BitField<int, 0, kLengthFieldSize>;
68   static const int kMaxLength = LengthField::kMax;
69   using HashField = base::BitField<int, kLengthFieldSize,
70                                    kSmiValueSize - kLengthFieldSize - 1>;
71 
72   static const int kNoHashSentinel = 0;
73 
74  private:
75   DECL_INT_ACCESSORS(length_and_hash)
76 
77   DECL_RELEASE_ACQUIRE_INT_ACCESSORS(length_and_hash)
78 
79   TQ_OBJECT_CONSTRUCTORS(PropertyArray)
80 };
81 
82 }  // namespace internal
83 }  // namespace v8
84 
85 #include "src/objects/object-macros-undef.h"
86 
87 #endif  // V8_OBJECTS_PROPERTY_ARRAY_H_
88