v8 12.4.254 (node 22.4.1)
V8 is Google's open source JavaScript engine
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 kPageSize = size_t{1} << 17;
34
35#if defined(V8_HOST_ARCH_ARM64) && defined(V8_OS_DARWIN)
36constexpr size_t kGuardPageSize = 0;
37#else
38constexpr size_t kGuardPageSize = 4096;
39#endif
40
41static constexpr size_t kLargeObjectSizeThreshold = kPageSize / 2;
42
43#if defined(CPPGC_POINTER_COMPRESSION)
44#if defined(CPPGC_ENABLE_LARGER_CAGE)
45constexpr unsigned kPointerCompressionShift = 3;
46#else // !defined(CPPGC_ENABLE_LARGER_CAGE)
47constexpr unsigned kPointerCompressionShift = 1;
48#endif // !defined(CPPGC_ENABLE_LARGER_CAGE)
49#endif // !defined(CPPGC_POINTER_COMPRESSION)
50
51#if defined(CPPGC_CAGED_HEAP)
52#if defined(CPPGC_2GB_CAGE)
53constexpr size_t kCagedHeapDefaultReservationSize =
54 static_cast<size_t>(2) * kGB;
55constexpr size_t kCagedHeapMaxReservationSize =
56 kCagedHeapDefaultReservationSize;
57#else // !defined(CPPGC_2GB_CAGE)
58constexpr size_t kCagedHeapDefaultReservationSize =
59 static_cast<size_t>(4) * kGB;
60#if defined(CPPGC_POINTER_COMPRESSION)
61constexpr size_t kCagedHeapMaxReservationSize =
62 size_t{1} << (31 + kPointerCompressionShift);
63#else // !defined(CPPGC_POINTER_COMPRESSION)
64constexpr size_t kCagedHeapMaxReservationSize =
65 kCagedHeapDefaultReservationSize;
66#endif // !defined(CPPGC_POINTER_COMPRESSION)
67#endif // !defined(CPPGC_2GB_CAGE)
68constexpr size_t kCagedHeapReservationAlignment = kCagedHeapMaxReservationSize;
69#endif // defined(CPPGC_CAGED_HEAP)
70
71static constexpr size_t kDefaultAlignment = sizeof(void*);
72
73// Maximum support alignment for a type as in `alignof(T)`.
74static constexpr size_t kMaxSupportedAlignment = 2 * kDefaultAlignment;
75
76// Granularity of heap allocations.
77constexpr size_t kAllocationGranularity = sizeof(void*);
78
79// Default cacheline size.
80constexpr size_t kCachelineSize = 64;
81
82} // namespace api_constants
83
84} // namespace internal
85} // namespace cppgc
86
87#endif // INCLUDE_CPPGC_INTERNAL_API_CONSTANTS_H_
constexpr size_t kAllocationGranularity