Loading...
Searching...
No Matches
api-constants.h
Go to the documentation of this file.
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#ifndef INCLUDE_CPPGC_INTERNAL_API_CONSTANTS_H_
6#define INCLUDE_CPPGC_INTERNAL_API_CONSTANTS_H_
7
8#include <cstddef>
9#include <cstdint>
10
11#include "v8config.h" // NOLINT(build/include_directory)
12
13namespace cppgc {
14namespace internal {
15
16// Embedders should not rely on this code!
17
18// Internal constants to avoid exposing internal types on the API surface.
19namespace api_constants {
20
21constexpr size_t kKB = 1024;
22constexpr size_t kMB = kKB * 1024;
23constexpr size_t kGB = kMB * 1024;
24
25// Offset of the uint16_t bitfield from the payload contaning the
26// in-construction bit. This is subtracted from the payload pointer to get
27// to the right bitfield.
28static constexpr size_t kFullyConstructedBitFieldOffsetFromPayload =
29 2 * sizeof(uint16_t);
30// Mask for in-construction bit.
31static constexpr uint16_t kFullyConstructedBitMask = uint16_t{1};
32
33static constexpr size_t kPageSizeBits = 17;
34static constexpr size_t kPageSize = size_t{1} << kPageSizeBits;
35
36#if defined(V8_HOST_ARCH_ARM64) && defined(V8_OS_DARWIN)
37constexpr size_t kGuardPageSize = 0;
38#elif defined(V8_HOST_ARCH_PPC64)
39constexpr size_t kGuardPageSize = 0;
40#elif defined(V8_HOST_ARCH_LOONG64) || defined(V8_HOST_ARCH_MIPS64)
41constexpr size_t kGuardPageSize = 0;
42#else
43constexpr size_t kGuardPageSize = 0;
44#endif
45
46static constexpr size_t kLargeObjectSizeThreshold = kPageSize / 2;
47
48#if defined(CPPGC_POINTER_COMPRESSION)
49#if defined(CPPGC_ENABLE_LARGER_CAGE)
50constexpr unsigned kPointerCompressionShift = 3;
51#else // !defined(CPPGC_ENABLE_LARGER_CAGE)
52constexpr unsigned kPointerCompressionShift = 1;
53#endif // !defined(CPPGC_ENABLE_LARGER_CAGE)
54#endif // !defined(CPPGC_POINTER_COMPRESSION)
55
56#if defined(CPPGC_CAGED_HEAP)
57constexpr size_t kCagedHeapDefaultReservationSize =
58 static_cast<size_t>(4) * kGB;
59#if defined(CPPGC_POINTER_COMPRESSION)
60constexpr size_t kCagedHeapMaxReservationSize =
61 size_t{1} << (31 + kPointerCompressionShift);
62#else // !defined(CPPGC_POINTER_COMPRESSION)
63constexpr size_t kCagedHeapMaxReservationSize =
64 kCagedHeapDefaultReservationSize;
65#endif // !defined(CPPGC_POINTER_COMPRESSION)
66constexpr size_t kCagedHeapReservationAlignment = kCagedHeapMaxReservationSize;
67#endif // defined(CPPGC_CAGED_HEAP)
68
69static constexpr size_t kDefaultAlignment = sizeof(void*);
70
71// Maximum support alignment for a type as in `alignof(T)`.
72static constexpr size_t kMaxSupportedAlignment = 2 * kDefaultAlignment;
73
74// Granularity of heap allocations.
75constexpr size_t kAllocationGranularity = sizeof(void*);
76
77// Default cacheline size.
78constexpr size_t kCachelineSize = 64;
79
80} // namespace api_constants
81
82} // namespace internal
83} // namespace cppgc
84
85#endif // INCLUDE_CPPGC_INTERNAL_API_CONSTANTS_H_
constexpr size_t kAllocationGranularity
Definition: api-constants.h:75
constexpr size_t kKB
Definition: api-constants.h:21
constexpr size_t kCachelineSize
Definition: api-constants.h:78
constexpr size_t kGB
Definition: api-constants.h:23
constexpr size_t kGuardPageSize
Definition: api-constants.h:43
constexpr size_t kMB
Definition: api-constants.h:22
Definition: allocation.h:38