v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
object-view.h
Go to the documentation of this file.
1// Copyright 2021 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_HEAP_CPPGC_OBJECT_VIEW_H_
6#define V8_HEAP_CPPGC_OBJECT_VIEW_H_
7
8#include "include/v8config.h"
12
13namespace cppgc {
14namespace internal {
15
16// ObjectView allows accessing a header within the bounds of the actual object.
17// It is not exposed externally and does not keep the underlying object alive.
18template <AccessMode = AccessMode::kNonAtomic>
19class ObjectView final {
20 public:
21 V8_INLINE explicit ObjectView(const HeapObjectHeader& header);
22
23 V8_INLINE Address Start() const;
25 V8_INLINE size_t Size() const;
26
27 private:
30 const bool is_large_object_;
31};
32
33template <AccessMode access_mode>
35 : header_(header),
36 base_page_(
37 BasePage::FromPayload(const_cast<HeapObjectHeader*>(&header_))),
38 is_large_object_(header_.IsLargeObject<access_mode>()) {
39 DCHECK_EQ(Start() + Size(), End());
40}
41
42template <AccessMode access_mode>
44 return header_.ObjectStart();
45}
46
47template <AccessMode access_mode>
49 return is_large_object_ ? LargePage::From(base_page_)->PayloadEnd()
50 : header_.ObjectEnd<access_mode>();
51}
52
53template <AccessMode access_mode>
55 return is_large_object_ ? LargePage::From(base_page_)->ObjectSize()
56 : header_.ObjectSize<access_mode>();
57}
58
59} // namespace internal
60} // namespace cppgc
61
62#endif // V8_HEAP_CPPGC_OBJECT_VIEW_H_
static LargePage * From(BasePage *page)
Definition heap-page.h:275
size_t ObjectSize() const
Definition heap-page.h:292
V8_INLINE size_t Size() const
Definition object-view.h:54
V8_INLINE Address Start() const
Definition object-view.h:43
V8_INLINE ObjectView(const HeapObjectHeader &header)
Definition object-view.h:34
const BasePage * base_page_
Definition object-view.h:29
const HeapObjectHeader & header_
Definition object-view.h:28
V8_INLINE ConstAddress End() const
Definition object-view.h:48
uint8_t * Address
Definition globals.h:17
const uint8_t * ConstAddress
Definition globals.h:18
#define DCHECK_EQ(v1, v2)
Definition logging.h:485
#define V8_INLINE
Definition v8config.h:500