v8  8.6.395 (node 15.0.1)
V8 is Google's open source JavaScript engine
pointer-policies.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_POINTER_POLICIES_H_
6 #define INCLUDE_CPPGC_INTERNAL_POINTER_POLICIES_H_
7 
8 #include <cstdint>
9 #include <type_traits>
10 
11 #include "cppgc/internal/write-barrier.h"
12 #include "cppgc/source-location.h"
13 #include "v8config.h" // NOLINT(build/include_directory)
14 
15 namespace cppgc {
16 namespace internal {
17 
18 class PersistentRegion;
19 
20 // Tags to distinguish between strong and weak member types.
21 class StrongMemberTag;
22 class WeakMemberTag;
23 class UntracedMemberTag;
24 
26  static void InitializingBarrier(const void*, const void*) {
27  // Since in initializing writes the source object is always white, having no
28  // barrier doesn't break the tri-color invariant.
29  }
30  static void AssigningBarrier(const void* slot, const void* value) {
31  WriteBarrier::MarkingBarrier(slot, value);
32  }
33 };
34 
36  static void InitializingBarrier(const void*, const void*) {}
37  static void AssigningBarrier(const void*, const void*) {}
38 };
39 
41  protected:
43  void CheckPointer(const void* ptr);
44 
45  private:
46  void* impl_;
47 };
48 
50  protected:
51  void CheckPointer(const void* raw) {}
52 };
53 
54 #if V8_ENABLE_CHECKS
56 #else
57 using DefaultCheckingPolicy = DisabledCheckingPolicy;
58 #endif
59 
61  public:
62  constexpr const SourceLocation& Location() const { return location_; }
63 
64  protected:
65  constexpr explicit KeepLocationPolicy(const SourceLocation& location)
66  : location_(location) {}
67 
68  // KeepLocationPolicy must not copy underlying source locations.
71 
72  // Location of the original moved from object should be preserved.
75 
76  private:
77  SourceLocation location_;
78 };
79 
81  public:
82  constexpr SourceLocation Location() const { return {}; }
83 
84  protected:
85  constexpr explicit IgnoreLocationPolicy(const SourceLocation&) {}
86 };
87 
88 #if CPPGC_SUPPORTS_OBJECT_NAMES
90 #else
91 using DefaultLocationPolicy = IgnoreLocationPolicy;
92 #endif
93 
95  using IsStrongPersistent = std::true_type;
96 
97  static V8_EXPORT PersistentRegion& GetPersistentRegion(void* object);
98 };
99 
101  using IsStrongPersistent = std::false_type;
102 
103  static V8_EXPORT PersistentRegion& GetPersistentRegion(void* object);
104 };
105 
106 // Persistent/Member forward declarations.
107 template <typename T, typename WeaknessPolicy,
108  typename LocationPolicy = DefaultLocationPolicy,
109  typename CheckingPolicy = DefaultCheckingPolicy>
110 class BasicPersistent;
111 template <typename T, typename WeaknessTag, typename WriteBarrierPolicy,
112  typename CheckingPolicy = DefaultCheckingPolicy>
113 class BasicMember;
114 
115 // Special tag type used to denote some sentinel member. The semantics of the
116 // sentinel is defined by the embedder.
118  template <typename T>
119  operator T*() const { // NOLINT
120  static constexpr intptr_t kSentinelValue = 1;
121  return reinterpret_cast<T*>(kSentinelValue);
122  }
123  // Hidden friends.
124  friend bool operator==(SentinelPointer, SentinelPointer) { return true; }
125  friend bool operator!=(SentinelPointer, SentinelPointer) { return false; }
126 };
127 
128 } // namespace internal
129 
131 
132 } // namespace cppgc
133 
134 #endif // INCLUDE_CPPGC_INTERNAL_POINTER_POLICIES_H_