v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
zone-type-traits.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 V8_ZONE_ZONE_TYPE_TRAITS_H_
6#define V8_ZONE_ZONE_TYPE_TRAITS_H_
7
9
10#ifdef V8_COMPRESS_ZONES
12#endif
13
14namespace v8 {
15namespace internal {
16
17template <typename T>
19
20// ZonePtrList is a ZoneList of pointers to ZoneObjects allocated in the same
21// zone as the list object.
22template <typename T>
24
25template <typename T>
26using FullZonePtr = T*;
27
28template <typename T>
30
31//
32// ZoneTypeTraits provides type aliases for compressed or full pointer
33// dependent types based on a static flag. It helps organizing fine-grained
34// control over which parts of the code base should use compressed zone
35// pointers.
36// For example:
37// using ZoneNodePtr = typename ZoneTypeTraits<kCompressGraphZone>::Ptr<Node>;
38//
39// or
40// template <typename T>
41// using AstZonePtr = typename ZoneTypeTraits<kCompressAstZone>::Ptr<T>;
42//
43template <bool kEnableCompression>
45
46template <>
47struct ZoneTypeTraits<false> {
48 template <typename T>
50};
51
52template <>
53struct ZoneTypeTraits<true> {
54 template <typename T>
56};
57
58// This requirement is necessary for being able to use memcopy in containers
59// of zone pointers.
60// TODO(ishell): Re-enable once compressed pointers are supported in containers.
61// static_assert(
62// std::is_trivially_copyable<
63// ZoneTypeTraits<COMPRESS_ZONES_BOOL>::Ptr<int>>::value,
64// "ZoneTypeTraits<COMPRESS_ZONES_BOOL>::Ptr<T> must be trivially
65// copyable");
66
67//
68// is_compressed_pointer<T> predicate can be used for checking if T is a
69// compressed pointer.
70//
71template <typename>
72struct is_compressed_pointer : std::false_type {};
73
74template <typename T>
75struct is_compressed_pointer<CompressedZonePtr<T>> : std::true_type {};
76
77template <typename T>
78struct is_compressed_pointer<const CompressedZonePtr<T>> : std::true_type {};
79
80} // namespace internal
81} // namespace v8
82
83#endif // V8_ZONE_ZONE_TYPE_TRAITS_H_