11cb0ef41Sopenharmony_ci// Copyright 2020 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#include "src/heap/cppgc/heap-object-header.h"
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci#include "include/cppgc/internal/api-constants.h"
81cb0ef41Sopenharmony_ci#include "src/base/macros.h"
91cb0ef41Sopenharmony_ci#include "src/base/sanitizer/asan.h"
101cb0ef41Sopenharmony_ci#include "src/heap/cppgc/gc-info-table.h"
111cb0ef41Sopenharmony_ci#include "src/heap/cppgc/heap-page.h"
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_cinamespace cppgc {
141cb0ef41Sopenharmony_cinamespace internal {
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ciSTATIC_ASSERT((kAllocationGranularity % sizeof(HeapObjectHeader)) == 0);
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_civoid HeapObjectHeader::CheckApiConstants() {
191cb0ef41Sopenharmony_ci  STATIC_ASSERT(api_constants::kFullyConstructedBitMask ==
201cb0ef41Sopenharmony_ci                FullyConstructedField::kMask);
211cb0ef41Sopenharmony_ci  STATIC_ASSERT(api_constants::kFullyConstructedBitFieldOffsetFromPayload ==
221cb0ef41Sopenharmony_ci                (sizeof(encoded_high_) + sizeof(encoded_low_)));
231cb0ef41Sopenharmony_ci}
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_civoid HeapObjectHeader::Finalize() {
261cb0ef41Sopenharmony_ci#ifdef V8_USE_ADDRESS_SANITIZER
271cb0ef41Sopenharmony_ci  const size_t size =
281cb0ef41Sopenharmony_ci      IsLargeObject()
291cb0ef41Sopenharmony_ci          ? LargePage::From(BasePage::FromPayload(this))->ObjectSize()
301cb0ef41Sopenharmony_ci          : ObjectSize();
311cb0ef41Sopenharmony_ci  ASAN_UNPOISON_MEMORY_REGION(ObjectStart(), size);
321cb0ef41Sopenharmony_ci#endif  // V8_USE_ADDRESS_SANITIZER
331cb0ef41Sopenharmony_ci  const GCInfo& gc_info = GlobalGCInfoTable::GCInfoFromIndex(GetGCInfoIndex());
341cb0ef41Sopenharmony_ci  if (gc_info.finalize) {
351cb0ef41Sopenharmony_ci    gc_info.finalize(ObjectStart());
361cb0ef41Sopenharmony_ci  }
371cb0ef41Sopenharmony_ci}
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_ciHeapObjectName HeapObjectHeader::GetName() const {
401cb0ef41Sopenharmony_ci  const GCInfo& gc_info = GlobalGCInfoTable::GCInfoFromIndex(GetGCInfoIndex());
411cb0ef41Sopenharmony_ci  return gc_info.name(ObjectStart());
421cb0ef41Sopenharmony_ci}
431cb0ef41Sopenharmony_ci
441cb0ef41Sopenharmony_ci}  // namespace internal
451cb0ef41Sopenharmony_ci}  // namespace cppgc
46