• 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_INL_H_
6 #define V8_OBJECTS_PROPERTY_ARRAY_INL_H_
7 
8 #include "src/objects/property-array.h"
9 
10 #include "src/heap/heap-write-barrier-inl.h"
11 #include "src/objects/heap-object-inl.h"
12 #include "src/objects/objects-inl.h"
13 #include "src/objects/smi-inl.h"
14 
15 // Has to be the last include (doesn't have include guards):
16 #include "src/objects/object-macros.h"
17 
18 namespace v8 {
19 namespace internal {
20 
OBJECT_CONSTRUCTORS_IMPL(PropertyArray,HeapObject)21 OBJECT_CONSTRUCTORS_IMPL(PropertyArray, HeapObject)
22 CAST_ACCESSOR(PropertyArray)
23 
24 SMI_ACCESSORS(PropertyArray, length_and_hash, kLengthAndHashOffset)
25 SYNCHRONIZED_SMI_ACCESSORS(PropertyArray, length_and_hash, kLengthAndHashOffset)
26 
27 Object PropertyArray::get(int index) const {
28   IsolateRoot isolate = GetIsolateForPtrCompr(*this);
29   return get(isolate, index);
30 }
31 
get(IsolateRoot isolate,int index)32 Object PropertyArray::get(IsolateRoot isolate, int index) const {
33   DCHECK_LT(static_cast<unsigned>(index),
34             static_cast<unsigned>(this->length()));
35   return TaggedField<Object>::Relaxed_Load(isolate, *this,
36                                            OffsetOfElementAt(index));
37 }
38 
set(int index,Object value)39 void PropertyArray::set(int index, Object value) {
40   DCHECK(IsPropertyArray());
41   DCHECK_LT(static_cast<unsigned>(index),
42             static_cast<unsigned>(this->length()));
43   int offset = OffsetOfElementAt(index);
44   RELAXED_WRITE_FIELD(*this, offset, value);
45   WRITE_BARRIER(*this, offset, value);
46 }
47 
set(int index,Object value,WriteBarrierMode mode)48 void PropertyArray::set(int index, Object value, WriteBarrierMode mode) {
49   DCHECK_LT(static_cast<unsigned>(index),
50             static_cast<unsigned>(this->length()));
51   int offset = OffsetOfElementAt(index);
52   RELAXED_WRITE_FIELD(*this, offset, value);
53   CONDITIONAL_WRITE_BARRIER(*this, offset, value, mode);
54 }
55 
data_start()56 ObjectSlot PropertyArray::data_start() { return RawField(kHeaderSize); }
57 
length()58 int PropertyArray::length() const {
59   return LengthField::decode(length_and_hash());
60 }
61 
initialize_length(int len)62 void PropertyArray::initialize_length(int len) {
63   DCHECK(LengthField::is_valid(len));
64   set_length_and_hash(len);
65 }
66 
synchronized_length()67 int PropertyArray::synchronized_length() const {
68   return LengthField::decode(synchronized_length_and_hash());
69 }
70 
Hash()71 int PropertyArray::Hash() const { return HashField::decode(length_and_hash()); }
72 
SetHash(int hash)73 void PropertyArray::SetHash(int hash) {
74   int value = length_and_hash();
75   value = HashField::update(value, hash);
76   set_length_and_hash(value);
77 }
78 
CopyElements(Isolate * isolate,int dst_index,PropertyArray src,int src_index,int len,WriteBarrierMode mode)79 void PropertyArray::CopyElements(Isolate* isolate, int dst_index,
80                                  PropertyArray src, int src_index, int len,
81                                  WriteBarrierMode mode) {
82   if (len == 0) return;
83   DisallowHeapAllocation no_gc;
84 
85   ObjectSlot dst_slot(data_start() + dst_index);
86   ObjectSlot src_slot(src.data_start() + src_index);
87   isolate->heap()->CopyRange(*this, dst_slot, src_slot, len, mode);
88 }
89 
90 }  // namespace internal
91 }  // namespace v8
92 
93 #include "src/objects/object-macros-undef.h"
94 
95 #endif  // V8_OBJECTS_PROPERTY_ARRAY_INL_H_
96