1// Copyright 2020 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#include "src/heap/cppgc/heap-object-header.h"
6
7#include "include/cppgc/internal/api-constants.h"
8#include "src/base/macros.h"
9#include "src/base/sanitizer/asan.h"
10#include "src/heap/cppgc/gc-info-table.h"
11#include "src/heap/cppgc/heap-page.h"
12
13namespace cppgc {
14namespace internal {
15
16STATIC_ASSERT((kAllocationGranularity % sizeof(HeapObjectHeader)) == 0);
17
18void HeapObjectHeader::CheckApiConstants() {
19  STATIC_ASSERT(api_constants::kFullyConstructedBitMask ==
20                FullyConstructedField::kMask);
21  STATIC_ASSERT(api_constants::kFullyConstructedBitFieldOffsetFromPayload ==
22                (sizeof(encoded_high_) + sizeof(encoded_low_)));
23}
24
25void HeapObjectHeader::Finalize() {
26#ifdef V8_USE_ADDRESS_SANITIZER
27  const size_t size =
28      IsLargeObject()
29          ? LargePage::From(BasePage::FromPayload(this))->ObjectSize()
30          : ObjectSize();
31  ASAN_UNPOISON_MEMORY_REGION(ObjectStart(), size);
32#endif  // V8_USE_ADDRESS_SANITIZER
33  const GCInfo& gc_info = GlobalGCInfoTable::GCInfoFromIndex(GetGCInfoIndex());
34  if (gc_info.finalize) {
35    gc_info.finalize(ObjectStart());
36  }
37}
38
39HeapObjectName HeapObjectHeader::GetName() const {
40  const GCInfo& gc_info = GlobalGCInfoTable::GCInfoFromIndex(GetGCInfoIndex());
41  return gc_info.name(ObjectStart());
42}
43
44}  // namespace internal
45}  // namespace cppgc
46