chromium/v8/src/heap/cppgc/heap-object-header.h

// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_HEAP_CPPGC_HEAP_OBJECT_HEADER_H_
#define V8_HEAP_CPPGC_HEAP_OBJECT_HEADER_H_

#include <stdint.h>

#include <atomic>

#include "include/cppgc/allocation.h"
#include "include/cppgc/internal/gc-info.h"
#include "include/cppgc/internal/member-storage.h"
#include "include/cppgc/internal/name-trait.h"
#include "src/base/atomic-utils.h"
#include "src/base/bit-field.h"
#include "src/base/logging.h"
#include "src/base/macros.h"
#include "src/heap/cppgc/gc-info-table.h"
#include "src/heap/cppgc/globals.h"

#if defined(CPPGC_CAGED_HEAP)
#include "src/heap/cppgc/caged-heap.h"
#endif  // defined(CPPGC_CAGED_HEAP)

namespace cppgc {

class Visitor;

namespace internal {

// HeapObjectHeader contains meta data per object and is prepended to each
// object.
//
// +-----------------+------+------------------------------------------+
// | name            | bits |                                          |
// +-----------------+------+------------------------------------------+
// | padding         |   32 | Only present on 64-bit platform.         |
// +-----------------+------+------------------------------------------+
// | GCInfoIndex     |   14 |                                          |
// | unused          |    1 |                                          |
// | in construction |    1 | In construction encoded as |false|.      |
// +-----------------+------+------------------------------------------+
// | size            |   15 | 17 bits because allocations are aligned. |
// | mark bit        |    1 |                                          |
// +-----------------+------+------------------------------------------+
//
// Notes:
// - See |GCInfoTable| for constraints on GCInfoIndex.
// - |size| for regular objects is encoded with 15 bits but can actually
//   represent sizes up to |kBlinkPageSize| (2^17) because allocations are
//   always 4 byte aligned (see kAllocationGranularity) on 32bit. 64bit uses
//   8 byte aligned allocations which leaves 1 bit unused.
// - |size| for large objects is encoded as 0. The size of a large object is
//   stored in |LargeObjectPage::PayloadSize()|.
// - |mark bit| and |in construction| bits are located in separate 16-bit halves
//    to allow potentially accessing them non-atomically.
class HeapObjectHeader {};

static_assert;

// static
HeapObjectHeader& HeapObjectHeader::FromObject(void* object) {}

// static
const HeapObjectHeader& HeapObjectHeader::FromObject(const void* object) {}

HeapObjectHeader::HeapObjectHeader(size_t size, GCInfoIndex gc_info_index) {}

Address HeapObjectHeader::ObjectStart() const {}

template <AccessMode mode>
Address HeapObjectHeader::ObjectEnd() const {}

template <AccessMode mode>
GCInfoIndex HeapObjectHeader::GetGCInfoIndex() const {}

template <AccessMode mode>
size_t HeapObjectHeader::AllocatedSize() const {}

void HeapObjectHeader::SetAllocatedSize(size_t size) {}

template <AccessMode mode>
size_t HeapObjectHeader::ObjectSize() const {}

template <AccessMode mode>
bool HeapObjectHeader::IsLargeObject() const {}

template <AccessMode mode>
bool HeapObjectHeader::IsInConstruction() const {}

void HeapObjectHeader::MarkAsFullyConstructed() {}

template <AccessMode mode>
bool HeapObjectHeader::IsMarked() const {}

template <AccessMode mode>
void HeapObjectHeader::Unmark() {}

bool HeapObjectHeader::TryMarkAtomic() {}

void HeapObjectHeader::MarkNonAtomic() {}

template <AccessMode mode>
bool HeapObjectHeader::IsYoung() const {}

template <AccessMode mode>
bool HeapObjectHeader::IsFree() const {}

bool HeapObjectHeader::IsFinalizable() const {}

#if defined(CPPGC_CAGED_HEAP)
void HeapObjectHeader::SetNextUnfinalized(HeapObjectHeader* next) {}

HeapObjectHeader* HeapObjectHeader::GetNextUnfinalized(
    uintptr_t cage_base_or_mask) const {}
#endif  // defined(CPPGC_CAGED_HEAP)

template <AccessMode mode>
void HeapObjectHeader::Trace(Visitor* visitor) const {}

template <AccessMode mode, HeapObjectHeader::EncodedHalf part,
          std::memory_order memory_order>
uint16_t HeapObjectHeader::LoadEncoded() const {}

template <AccessMode mode, HeapObjectHeader::EncodedHalf part,
          std::memory_order memory_order>
void HeapObjectHeader::StoreEncoded(uint16_t bits, uint16_t mask) {}

}  // namespace internal
}  // namespace cppgc

#endif  // V8_HEAP_CPPGC_HEAP_OBJECT_HEADER_H_