11cb0ef41Sopenharmony_ci// Copyright 2018 the V8 project authors. All rights reserved. 21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be 31cb0ef41Sopenharmony_ci// found in the LICENSE file. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci#ifndef V8_OBJECTS_PROPERTY_ARRAY_INL_H_ 61cb0ef41Sopenharmony_ci#define V8_OBJECTS_PROPERTY_ARRAY_INL_H_ 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci#include "src/objects/property-array.h" 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ci#include "src/heap/heap-write-barrier-inl.h" 111cb0ef41Sopenharmony_ci#include "src/objects/heap-object-inl.h" 121cb0ef41Sopenharmony_ci#include "src/objects/objects-inl.h" 131cb0ef41Sopenharmony_ci#include "src/objects/smi-inl.h" 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ci// Has to be the last include (doesn't have include guards): 161cb0ef41Sopenharmony_ci#include "src/objects/object-macros.h" 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_cinamespace v8 { 191cb0ef41Sopenharmony_cinamespace internal { 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ci#include "torque-generated/src/objects/property-array-tq-inl.inc" 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ciTQ_OBJECT_CONSTRUCTORS_IMPL(PropertyArray) 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ciSMI_ACCESSORS(PropertyArray, length_and_hash, kLengthAndHashOffset) 261cb0ef41Sopenharmony_ciRELEASE_ACQUIRE_SMI_ACCESSORS(PropertyArray, length_and_hash, 271cb0ef41Sopenharmony_ci kLengthAndHashOffset) 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ciObject PropertyArray::get(int index) const { 301cb0ef41Sopenharmony_ci PtrComprCageBase cage_base = GetPtrComprCageBase(*this); 311cb0ef41Sopenharmony_ci return get(cage_base, index); 321cb0ef41Sopenharmony_ci} 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ciObject PropertyArray::get(PtrComprCageBase cage_base, int index) const { 351cb0ef41Sopenharmony_ci DCHECK_LT(static_cast<unsigned>(index), 361cb0ef41Sopenharmony_ci static_cast<unsigned>(this->length(kAcquireLoad))); 371cb0ef41Sopenharmony_ci return TaggedField<Object>::Relaxed_Load(cage_base, *this, 381cb0ef41Sopenharmony_ci OffsetOfElementAt(index)); 391cb0ef41Sopenharmony_ci} 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_ciObject PropertyArray::get(int index, SeqCstAccessTag tag) const { 421cb0ef41Sopenharmony_ci PtrComprCageBase cage_base = GetPtrComprCageBase(*this); 431cb0ef41Sopenharmony_ci return get(cage_base, index, tag); 441cb0ef41Sopenharmony_ci} 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ciObject PropertyArray::get(PtrComprCageBase cage_base, int index, 471cb0ef41Sopenharmony_ci SeqCstAccessTag tag) const { 481cb0ef41Sopenharmony_ci DCHECK_LT(static_cast<unsigned>(index), 491cb0ef41Sopenharmony_ci static_cast<unsigned>(this->length(kAcquireLoad))); 501cb0ef41Sopenharmony_ci return TaggedField<Object>::SeqCst_Load(cage_base, *this, 511cb0ef41Sopenharmony_ci OffsetOfElementAt(index)); 521cb0ef41Sopenharmony_ci} 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_civoid PropertyArray::set(int index, Object value) { 551cb0ef41Sopenharmony_ci DCHECK(IsPropertyArray()); 561cb0ef41Sopenharmony_ci DCHECK_LT(static_cast<unsigned>(index), 571cb0ef41Sopenharmony_ci static_cast<unsigned>(this->length(kAcquireLoad))); 581cb0ef41Sopenharmony_ci int offset = OffsetOfElementAt(index); 591cb0ef41Sopenharmony_ci RELAXED_WRITE_FIELD(*this, offset, value); 601cb0ef41Sopenharmony_ci WRITE_BARRIER(*this, offset, value); 611cb0ef41Sopenharmony_ci} 621cb0ef41Sopenharmony_ci 631cb0ef41Sopenharmony_civoid PropertyArray::set(int index, Object value, WriteBarrierMode mode) { 641cb0ef41Sopenharmony_ci DCHECK_LT(static_cast<unsigned>(index), 651cb0ef41Sopenharmony_ci static_cast<unsigned>(this->length(kAcquireLoad))); 661cb0ef41Sopenharmony_ci int offset = OffsetOfElementAt(index); 671cb0ef41Sopenharmony_ci RELAXED_WRITE_FIELD(*this, offset, value); 681cb0ef41Sopenharmony_ci CONDITIONAL_WRITE_BARRIER(*this, offset, value, mode); 691cb0ef41Sopenharmony_ci} 701cb0ef41Sopenharmony_ci 711cb0ef41Sopenharmony_civoid PropertyArray::set(int index, Object value, SeqCstAccessTag tag) { 721cb0ef41Sopenharmony_ci DCHECK(IsPropertyArray()); 731cb0ef41Sopenharmony_ci DCHECK_LT(static_cast<unsigned>(index), 741cb0ef41Sopenharmony_ci static_cast<unsigned>(this->length(kAcquireLoad))); 751cb0ef41Sopenharmony_ci DCHECK(value.IsShared()); 761cb0ef41Sopenharmony_ci int offset = OffsetOfElementAt(index); 771cb0ef41Sopenharmony_ci SEQ_CST_WRITE_FIELD(*this, offset, value); 781cb0ef41Sopenharmony_ci // JSSharedStructs are allocated in the shared old space, which is currently 791cb0ef41Sopenharmony_ci // collected by stopping the world, so the incremental write barrier is not 801cb0ef41Sopenharmony_ci // needed. They can only store Smis and other HeapObjects in the shared old 811cb0ef41Sopenharmony_ci // space, so the generational write barrier is also not needed. 821cb0ef41Sopenharmony_ci} 831cb0ef41Sopenharmony_ci 841cb0ef41Sopenharmony_ciObject PropertyArray::Swap(int index, Object value, SeqCstAccessTag tag) { 851cb0ef41Sopenharmony_ci PtrComprCageBase cage_base = GetPtrComprCageBase(*this); 861cb0ef41Sopenharmony_ci return Swap(cage_base, index, value, tag); 871cb0ef41Sopenharmony_ci} 881cb0ef41Sopenharmony_ci 891cb0ef41Sopenharmony_ciObject PropertyArray::Swap(PtrComprCageBase cage_base, int index, Object value, 901cb0ef41Sopenharmony_ci SeqCstAccessTag tag) { 911cb0ef41Sopenharmony_ci DCHECK(IsPropertyArray()); 921cb0ef41Sopenharmony_ci DCHECK_LT(static_cast<unsigned>(index), 931cb0ef41Sopenharmony_ci static_cast<unsigned>(this->length(kAcquireLoad))); 941cb0ef41Sopenharmony_ci DCHECK(value.IsShared()); 951cb0ef41Sopenharmony_ci return TaggedField<Object>::SeqCst_Swap(cage_base, *this, 961cb0ef41Sopenharmony_ci OffsetOfElementAt(index), value); 971cb0ef41Sopenharmony_ci // JSSharedStructs are allocated in the shared old space, which is currently 981cb0ef41Sopenharmony_ci // collected by stopping the world, so the incremental write barrier is not 991cb0ef41Sopenharmony_ci // needed. They can only store Smis and other HeapObjects in the shared old 1001cb0ef41Sopenharmony_ci // space, so the generational write barrier is also not needed. 1011cb0ef41Sopenharmony_ci} 1021cb0ef41Sopenharmony_ci 1031cb0ef41Sopenharmony_ciObjectSlot PropertyArray::data_start() { return RawField(kHeaderSize); } 1041cb0ef41Sopenharmony_ci 1051cb0ef41Sopenharmony_ciint PropertyArray::length() const { 1061cb0ef41Sopenharmony_ci return LengthField::decode(length_and_hash()); 1071cb0ef41Sopenharmony_ci} 1081cb0ef41Sopenharmony_ci 1091cb0ef41Sopenharmony_civoid PropertyArray::initialize_length(int len) { 1101cb0ef41Sopenharmony_ci DCHECK(LengthField::is_valid(len)); 1111cb0ef41Sopenharmony_ci set_length_and_hash(len); 1121cb0ef41Sopenharmony_ci} 1131cb0ef41Sopenharmony_ci 1141cb0ef41Sopenharmony_ciint PropertyArray::length(AcquireLoadTag) const { 1151cb0ef41Sopenharmony_ci return LengthField::decode(length_and_hash(kAcquireLoad)); 1161cb0ef41Sopenharmony_ci} 1171cb0ef41Sopenharmony_ci 1181cb0ef41Sopenharmony_ciint PropertyArray::Hash() const { return HashField::decode(length_and_hash()); } 1191cb0ef41Sopenharmony_ci 1201cb0ef41Sopenharmony_civoid PropertyArray::SetHash(int hash) { 1211cb0ef41Sopenharmony_ci int value = length_and_hash(); 1221cb0ef41Sopenharmony_ci value = HashField::update(value, hash); 1231cb0ef41Sopenharmony_ci set_length_and_hash(value, kReleaseStore); 1241cb0ef41Sopenharmony_ci} 1251cb0ef41Sopenharmony_ci 1261cb0ef41Sopenharmony_civoid PropertyArray::CopyElements(Isolate* isolate, int dst_index, 1271cb0ef41Sopenharmony_ci PropertyArray src, int src_index, int len, 1281cb0ef41Sopenharmony_ci WriteBarrierMode mode) { 1291cb0ef41Sopenharmony_ci if (len == 0) return; 1301cb0ef41Sopenharmony_ci DisallowGarbageCollection no_gc; 1311cb0ef41Sopenharmony_ci 1321cb0ef41Sopenharmony_ci ObjectSlot dst_slot(data_start() + dst_index); 1331cb0ef41Sopenharmony_ci ObjectSlot src_slot(src.data_start() + src_index); 1341cb0ef41Sopenharmony_ci isolate->heap()->CopyRange(*this, dst_slot, src_slot, len, mode); 1351cb0ef41Sopenharmony_ci} 1361cb0ef41Sopenharmony_ci 1371cb0ef41Sopenharmony_ci} // namespace internal 1381cb0ef41Sopenharmony_ci} // namespace v8 1391cb0ef41Sopenharmony_ci 1401cb0ef41Sopenharmony_ci#include "src/objects/object-macros-undef.h" 1411cb0ef41Sopenharmony_ci 1421cb0ef41Sopenharmony_ci#endif // V8_OBJECTS_PROPERTY_ARRAY_INL_H_ 143