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#include "torque-generated/class-definitions-from-dsl.h"
10
11// Has to be the last include (doesn't have include guards):
12#include "src/objects/object-macros.h"
13
14namespace v8 {
15namespace internal {
16
17class PropertyArray : public HeapObject {
18 public:
19 // [length]: length of the array.
20 inline int length() const;
21
22 // Get the length using acquire loads.
23 inline int synchronized_length() 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
34 inline void set(int index, Object value);
35 // Setter with explicit barrier mode.
36 inline void set(int index, Object value, WriteBarrierMode mode);
37
38 // Gives access to raw memory which stores the array's data.
39 inline ObjectSlot data_start();
40
41 // Garbage collection support.
42 static constexpr int SizeFor(int length) {
43 return kHeaderSize + length * kTaggedSize;
44 }
45 static constexpr int OffsetOfElementAt(int index) { return SizeFor(index); }
46
47 DECL_CAST(PropertyArray)
48 DECL_PRINTER(PropertyArray)
49 DECL_VERIFIER(PropertyArray)
50
51 DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize,
52 TORQUE_GENERATED_PROPERTY_ARRAY_FIELDS)
53 static const int kHeaderSize = kSize;
54
55 // Garbage collection support.
56 using BodyDescriptor = FlexibleBodyDescriptor<kHeaderSize>;
57
58 static const int kLengthFieldSize = 10;
59 class LengthField : public BitField<int, 0, kLengthFieldSize> {};
60 static const int kMaxLength = LengthField::kMax;
61 class HashField : public BitField<int, kLengthFieldSize,
62 kSmiValueSize - kLengthFieldSize - 1> {};
63
64 static const int kNoHashSentinel = 0;
65
66 OBJECT_CONSTRUCTORS(PropertyArray, HeapObject);
67};
68
69} // namespace internal
70} // namespace v8
71
72#include "src/objects/object-macros-undef.h"
73
74#endif // V8_OBJECTS_PROPERTY_ARRAY_H_
75