libv8-node 15.14.0.1-x86_64-linux → 16.10.0.0-x86_64-linux

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/ext/libv8-node/location.rb +1 -1
  3. data/ext/libv8-node/paths.rb +1 -1
  4. data/lib/libv8/node/version.rb +3 -3
  5. data/vendor/v8/include/cppgc/allocation.h +104 -45
  6. data/vendor/v8/include/cppgc/common.h +9 -6
  7. data/vendor/v8/include/cppgc/cross-thread-persistent.h +384 -0
  8. data/vendor/v8/include/cppgc/custom-space.h +37 -2
  9. data/vendor/v8/include/cppgc/default-platform.h +47 -48
  10. data/vendor/v8/include/cppgc/ephemeron-pair.h +30 -0
  11. data/vendor/v8/include/cppgc/explicit-management.h +82 -0
  12. data/vendor/v8/include/cppgc/garbage-collected.h +4 -3
  13. data/vendor/v8/include/cppgc/heap-consistency.h +236 -0
  14. data/vendor/v8/include/cppgc/heap-state.h +70 -0
  15. data/vendor/v8/include/cppgc/heap-statistics.h +120 -0
  16. data/vendor/v8/include/cppgc/heap.h +68 -6
  17. data/vendor/v8/include/cppgc/internal/api-constants.h +3 -3
  18. data/vendor/v8/include/cppgc/internal/caged-heap-local-data.h +2 -1
  19. data/vendor/v8/include/cppgc/internal/compiler-specific.h +2 -2
  20. data/vendor/v8/include/cppgc/internal/gc-info.h +44 -13
  21. data/vendor/v8/include/cppgc/internal/name-trait.h +111 -0
  22. data/vendor/v8/include/cppgc/internal/persistent-node.h +57 -1
  23. data/vendor/v8/include/cppgc/internal/pointer-policies.h +69 -28
  24. data/vendor/v8/include/cppgc/internal/prefinalizer-handler.h +1 -1
  25. data/vendor/v8/include/cppgc/internal/write-barrier.h +353 -35
  26. data/vendor/v8/include/cppgc/liveness-broker.h +7 -1
  27. data/vendor/v8/include/cppgc/macros.h +2 -0
  28. data/vendor/v8/include/cppgc/member.h +85 -25
  29. data/vendor/v8/include/cppgc/name-provider.h +65 -0
  30. data/vendor/v8/include/cppgc/object-size-trait.h +58 -0
  31. data/vendor/v8/include/cppgc/persistent.h +33 -9
  32. data/vendor/v8/include/cppgc/platform.h +48 -25
  33. data/vendor/v8/include/cppgc/prefinalizer.h +1 -1
  34. data/vendor/v8/include/cppgc/process-heap-statistics.h +36 -0
  35. data/vendor/v8/include/cppgc/sentinel-pointer.h +32 -0
  36. data/vendor/v8/include/cppgc/source-location.h +2 -1
  37. data/vendor/v8/include/cppgc/testing.h +99 -0
  38. data/vendor/v8/include/cppgc/trace-trait.h +8 -3
  39. data/vendor/v8/include/cppgc/type-traits.h +157 -19
  40. data/vendor/v8/include/cppgc/visitor.h +187 -23
  41. data/vendor/v8/include/libplatform/libplatform.h +11 -0
  42. data/vendor/v8/include/libplatform/v8-tracing.h +2 -0
  43. data/vendor/v8/include/v8-cppgc.h +258 -159
  44. data/vendor/v8/include/v8-fast-api-calls.h +562 -159
  45. data/vendor/v8/include/v8-inspector.h +23 -2
  46. data/vendor/v8/include/v8-internal.h +99 -27
  47. data/vendor/v8/include/v8-metrics.h +77 -8
  48. data/vendor/v8/include/v8-platform.h +47 -22
  49. data/vendor/v8/include/v8-profiler.h +75 -11
  50. data/vendor/v8/include/v8-unwinder-state.h +30 -0
  51. data/vendor/v8/include/v8-util.h +1 -1
  52. data/vendor/v8/include/v8-version.h +4 -4
  53. data/vendor/v8/include/v8.h +1192 -642
  54. data/vendor/v8/include/v8config.h +40 -9
  55. data/vendor/v8/{out.gn → x86_64-linux}/libv8/obj/libv8_monolith.a +0 -0
  56. metadata +17 -5
  57. data/vendor/v8/include/cppgc/internal/process-heap.h +0 -34
@@ -0,0 +1,120 @@
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 INCLUDE_CPPGC_HEAP_STATISTICS_H_
6
+ #define INCLUDE_CPPGC_HEAP_STATISTICS_H_
7
+
8
+ #include <cstddef>
9
+ #include <cstdint>
10
+ #include <string>
11
+ #include <vector>
12
+
13
+ namespace cppgc {
14
+
15
+ /**
16
+ * `HeapStatistics` contains memory consumption and utilization statistics for a
17
+ * cppgc heap.
18
+ */
19
+ struct HeapStatistics final {
20
+ /**
21
+ * Specifies the detail level of the heap statistics. Brief statistics contain
22
+ * only the top-level allocated and used memory statistics for the entire
23
+ * heap. Detailed statistics also contain a break down per space and page, as
24
+ * well as freelist statistics and object type histograms. Note that used
25
+ * memory reported by brief statistics and detailed statistics might differ
26
+ * slightly.
27
+ */
28
+ enum DetailLevel : uint8_t {
29
+ kBrief,
30
+ kDetailed,
31
+ };
32
+
33
+ /**
34
+ * Object statistics for a single type.
35
+ */
36
+ struct ObjectStatsEntry {
37
+ /**
38
+ * Number of allocated bytes.
39
+ */
40
+ size_t allocated_bytes;
41
+ /**
42
+ * Number of allocated objects.
43
+ */
44
+ size_t object_count;
45
+ };
46
+
47
+ /**
48
+ * Page granularity statistics. For each page the statistics record the
49
+ * allocated memory size and overall used memory size for the page.
50
+ */
51
+ struct PageStatistics {
52
+ /** Overall committed amount of memory for the page. */
53
+ size_t committed_size_bytes = 0;
54
+ /** Resident amount of memory held by the page. */
55
+ size_t resident_size_bytes = 0;
56
+ /** Amount of memory actually used on the page. */
57
+ size_t used_size_bytes = 0;
58
+ /** Statistics for object allocated on the page. Filled only when
59
+ * NameProvider::HideInternalNames() is false. */
60
+ std::vector<ObjectStatsEntry> object_statistics;
61
+ };
62
+
63
+ /**
64
+ * Statistics of the freelist (used only in non-large object spaces). For
65
+ * each bucket in the freelist the statistics record the bucket size, the
66
+ * number of freelist entries in the bucket, and the overall allocated memory
67
+ * consumed by these freelist entries.
68
+ */
69
+ struct FreeListStatistics {
70
+ /** bucket sizes in the freelist. */
71
+ std::vector<size_t> bucket_size;
72
+ /** number of freelist entries per bucket. */
73
+ std::vector<size_t> free_count;
74
+ /** memory size consumed by freelist entries per size. */
75
+ std::vector<size_t> free_size;
76
+ };
77
+
78
+ /**
79
+ * Space granularity statistics. For each space the statistics record the
80
+ * space name, the amount of allocated memory and overall used memory for the
81
+ * space. The statistics also contain statistics for each of the space's
82
+ * pages, its freelist and the objects allocated on the space.
83
+ */
84
+ struct SpaceStatistics {
85
+ /** The space name */
86
+ std::string name;
87
+ /** Overall committed amount of memory for the heap. */
88
+ size_t committed_size_bytes = 0;
89
+ /** Resident amount of memory held by the heap. */
90
+ size_t resident_size_bytes = 0;
91
+ /** Amount of memory actually used on the space. */
92
+ size_t used_size_bytes = 0;
93
+ /** Statistics for each of the pages in the space. */
94
+ std::vector<PageStatistics> page_stats;
95
+ /** Statistics for the freelist of the space. */
96
+ FreeListStatistics free_list_stats;
97
+ };
98
+
99
+ /** Overall committed amount of memory for the heap. */
100
+ size_t committed_size_bytes = 0;
101
+ /** Resident amount of memory help by the heap. */
102
+ size_t resident_size_bytes = 0;
103
+ /** Amount of memory actually used on the heap. */
104
+ size_t used_size_bytes = 0;
105
+ /** Detail level of this HeapStatistics. */
106
+ DetailLevel detail_level;
107
+
108
+ /** Statistics for each of the spaces in the heap. Filled only when
109
+ * `detail_level` is `DetailLevel::kDetailed`. */
110
+ std::vector<SpaceStatistics> space_stats;
111
+
112
+ /**
113
+ * Vector of `cppgc::GarbageCollected` type names.
114
+ */
115
+ std::vector<std::string> type_names;
116
+ };
117
+
118
+ } // namespace cppgc
119
+
120
+ #endif // INCLUDE_CPPGC_HEAP_STATISTICS_H_
@@ -5,6 +5,8 @@
5
5
  #ifndef INCLUDE_CPPGC_HEAP_H_
6
6
  #define INCLUDE_CPPGC_HEAP_H_
7
7
 
8
+ #include <cstddef>
9
+ #include <cstdint>
8
10
  #include <memory>
9
11
  #include <vector>
10
12
 
@@ -29,6 +31,11 @@ namespace internal {
29
31
  class Heap;
30
32
  } // namespace internal
31
33
 
34
+ /**
35
+ * Used for additional heap APIs.
36
+ */
37
+ class HeapHandle;
38
+
32
39
  class V8_EXPORT Heap {
33
40
  public:
34
41
  /**
@@ -51,6 +58,41 @@ class V8_EXPORT Heap {
51
58
  kNoConservativeStackScan,
52
59
  };
53
60
 
61
+ /**
62
+ * Specifies supported marking types
63
+ */
64
+ enum class MarkingType : uint8_t {
65
+ /**
66
+ * Atomic stop-the-world marking. This option does not require any write
67
+ * barriers but is the most intrusive in terms of jank.
68
+ */
69
+ kAtomic,
70
+ /**
71
+ * Incremental marking, i.e. interleave marking is the rest of the
72
+ * application on the same thread.
73
+ */
74
+ kIncremental,
75
+ /**
76
+ * Incremental and concurrent marking.
77
+ */
78
+ kIncrementalAndConcurrent
79
+ };
80
+
81
+ /**
82
+ * Specifies supported sweeping types
83
+ */
84
+ enum class SweepingType : uint8_t {
85
+ /**
86
+ * Atomic stop-the-world sweeping. All of sweeping is performed at once.
87
+ */
88
+ kAtomic,
89
+ /**
90
+ * Incremental and concurrent sweeping. Sweeping is split and interleaved
91
+ * with the rest of the application.
92
+ */
93
+ kIncrementalAndConcurrent
94
+ };
95
+
54
96
  /**
55
97
  * Constraints for a Heap setup.
56
98
  */
@@ -66,33 +108,43 @@ class V8_EXPORT Heap {
66
108
 
67
109
  /**
68
110
  * Options specifying Heap properties (e.g. custom spaces) when initializing a
69
- * heap through Heap::Create().
111
+ * heap through `Heap::Create()`.
70
112
  */
71
113
  struct HeapOptions {
72
114
  /**
73
115
  * Creates reasonable defaults for instantiating a Heap.
74
116
  *
75
- * \returns the HeapOptions that can be passed to Heap::Create().
117
+ * \returns the HeapOptions that can be passed to `Heap::Create()`.
76
118
  */
77
119
  static HeapOptions Default() { return {}; }
78
120
 
79
121
  /**
80
122
  * Custom spaces added to heap are required to have indices forming a
81
- * numbered sequence starting at 0, i.e., their kSpaceIndex must correspond
82
- * to the index they reside in the vector.
123
+ * numbered sequence starting at 0, i.e., their `kSpaceIndex` must
124
+ * correspond to the index they reside in the vector.
83
125
  */
84
126
  std::vector<std::unique_ptr<CustomSpaceBase>> custom_spaces;
85
127
 
86
128
  /**
87
- * Specifies whether conserative stack scan is supported. When conservative
129
+ * Specifies whether conservative stack scan is supported. When conservative
88
130
  * stack scan is not supported, the collector may try to invoke
89
131
  * garbage collections using non-nestable task, which are guaranteed to have
90
132
  * no interesting stack, through the provided Platform. If such tasks are
91
133
  * not supported by the Platform, the embedder must take care of invoking
92
- * the GC through ForceGarbageCollectionSlow().
134
+ * the GC through `ForceGarbageCollectionSlow()`.
93
135
  */
94
136
  StackSupport stack_support = StackSupport::kSupportsConservativeStackScan;
95
137
 
138
+ /**
139
+ * Specifies which types of marking are supported by the heap.
140
+ */
141
+ MarkingType marking_support = MarkingType::kIncrementalAndConcurrent;
142
+
143
+ /**
144
+ * Specifies which types of sweeping are supported by the heap.
145
+ */
146
+ SweepingType sweeping_support = SweepingType::kIncrementalAndConcurrent;
147
+
96
148
  /**
97
149
  * Resource constraints specifying various properties that the internal
98
150
  * GC scheduler follows.
@@ -126,8 +178,18 @@ class V8_EXPORT Heap {
126
178
  const char* source, const char* reason,
127
179
  StackState stack_state = StackState::kMayContainHeapPointers);
128
180
 
181
+ /**
182
+ * \returns the opaque handle for allocating objects using
183
+ * `MakeGarbageCollected()`.
184
+ */
129
185
  AllocationHandle& GetAllocationHandle();
130
186
 
187
+ /**
188
+ * \returns the opaque heap handle which may be used to refer to this heap in
189
+ * other APIs. Valid as long as the underlying `Heap` is alive.
190
+ */
191
+ HeapHandle& GetHeapHandle();
192
+
131
193
  private:
132
194
  Heap() = default;
133
195
 
@@ -5,8 +5,8 @@
5
5
  #ifndef INCLUDE_CPPGC_INTERNAL_API_CONSTANTS_H_
6
6
  #define INCLUDE_CPPGC_INTERNAL_API_CONSTANTS_H_
7
7
 
8
- #include <stddef.h>
9
- #include <stdint.h>
8
+ #include <cstddef>
9
+ #include <cstdint>
10
10
 
11
11
  #include "v8config.h" // NOLINT(build/include_directory)
12
12
 
@@ -28,7 +28,7 @@ constexpr size_t kGB = kMB * 1024;
28
28
  static constexpr size_t kFullyConstructedBitFieldOffsetFromPayload =
29
29
  2 * sizeof(uint16_t);
30
30
  // Mask for in-construction bit.
31
- static constexpr size_t kFullyConstructedBitMask = size_t{1};
31
+ static constexpr uint16_t kFullyConstructedBitMask = uint16_t{1};
32
32
 
33
33
  static constexpr size_t kPageSize = size_t{1} << 17;
34
34
 
@@ -10,6 +10,7 @@
10
10
  #include "cppgc/internal/api-constants.h"
11
11
  #include "cppgc/internal/logging.h"
12
12
  #include "cppgc/platform.h"
13
+ #include "v8config.h" // NOLINT(build/include_directory)
13
14
 
14
15
  namespace cppgc {
15
16
  namespace internal {
@@ -54,7 +55,7 @@ static_assert(sizeof(AgeTable) == 1 * api_constants::kMB,
54
55
  struct CagedHeapLocalData final {
55
56
  explicit CagedHeapLocalData(HeapBase* heap_base) : heap_base(heap_base) {}
56
57
 
57
- bool is_marking_in_progress = false;
58
+ bool is_incremental_marking_in_progress = false;
58
59
  HeapBase* heap_base = nullptr;
59
60
  #if defined(CPPGC_YOUNG_GENERATION)
60
61
  AgeTable age_table;
@@ -21,13 +21,13 @@ namespace cppgc {
21
21
 
22
22
  // [[no_unique_address]] comes in C++20 but supported in clang with -std >=
23
23
  // c++11.
24
- #if CPPGC_HAS_CPP_ATTRIBUTE(no_unique_address) // NOLINTNEXTLINE
24
+ #if CPPGC_HAS_CPP_ATTRIBUTE(no_unique_address)
25
25
  #define CPPGC_NO_UNIQUE_ADDRESS [[no_unique_address]]
26
26
  #else
27
27
  #define CPPGC_NO_UNIQUE_ADDRESS
28
28
  #endif
29
29
 
30
- #if CPPGC_HAS_ATTRIBUTE(unused) // NOLINTNEXTLINE
30
+ #if CPPGC_HAS_ATTRIBUTE(unused)
31
31
  #define CPPGC_UNUSED __attribute__((unused))
32
32
  #else
33
33
  #define CPPGC_UNUSED
@@ -5,9 +5,12 @@
5
5
  #ifndef INCLUDE_CPPGC_INTERNAL_GC_INFO_H_
6
6
  #define INCLUDE_CPPGC_INTERNAL_GC_INFO_H_
7
7
 
8
- #include <stdint.h>
8
+ #include <atomic>
9
+ #include <cstdint>
10
+ #include <type_traits>
9
11
 
10
12
  #include "cppgc/internal/finalizer-trait.h"
13
+ #include "cppgc/internal/name-trait.h"
11
14
  #include "cppgc/trace-trait.h"
12
15
  #include "v8config.h" // NOLINT(build/include_directory)
13
16
 
@@ -16,26 +19,54 @@ namespace internal {
16
19
 
17
20
  using GCInfoIndex = uint16_t;
18
21
 
19
- class V8_EXPORT RegisteredGCInfoIndex final {
20
- public:
21
- RegisteredGCInfoIndex(FinalizationCallback finalization_callback,
22
- TraceCallback trace_callback, bool has_v_table);
23
- GCInfoIndex GetIndex() const { return index_; }
22
+ // Acquires a new GC info object and returns the index. In addition, also
23
+ // updates `registered_index` atomically.
24
+ V8_EXPORT GCInfoIndex
25
+ EnsureGCInfoIndex(std::atomic<GCInfoIndex>& registered_index,
26
+ FinalizationCallback, TraceCallback, NameCallback, bool);
24
27
 
25
- private:
26
- const GCInfoIndex index_;
28
+ // Fold types based on finalizer behavior. Note that finalizer characteristics
29
+ // align with trace behavior, i.e., destructors are virtual when trace methods
30
+ // are and vice versa.
31
+ template <typename T, typename ParentMostGarbageCollectedType>
32
+ struct GCInfoFolding {
33
+ static constexpr bool kHasVirtualDestructorAtBase =
34
+ std::has_virtual_destructor<ParentMostGarbageCollectedType>::value;
35
+ static constexpr bool kBothTypesAreTriviallyDestructible =
36
+ std::is_trivially_destructible<ParentMostGarbageCollectedType>::value &&
37
+ std::is_trivially_destructible<T>::value;
38
+ static constexpr bool kHasCustomFinalizerDispatchAtBase =
39
+ internal::HasFinalizeGarbageCollectedObject<
40
+ ParentMostGarbageCollectedType>::value;
41
+ #ifdef CPPGC_SUPPORTS_OBJECT_NAMES
42
+ static constexpr bool kWantsDetailedObjectNames = true;
43
+ #else // !CPPGC_SUPPORTS_OBJECT_NAMES
44
+ static constexpr bool kWantsDetailedObjectNames = false;
45
+ #endif // !CPPGC_SUPPORTS_OBJECT_NAMES
46
+
47
+ // Folding would regresses name resolution when deriving names from C++
48
+ // class names as it would just folds a name to the base class name.
49
+ using ResultType = std::conditional_t<(kHasVirtualDestructorAtBase ||
50
+ kBothTypesAreTriviallyDestructible ||
51
+ kHasCustomFinalizerDispatchAtBase) &&
52
+ !kWantsDetailedObjectNames,
53
+ ParentMostGarbageCollectedType, T>;
27
54
  };
28
55
 
29
56
  // Trait determines how the garbage collector treats objects wrt. to traversing,
30
57
  // finalization, and naming.
31
58
  template <typename T>
32
- struct GCInfoTrait {
59
+ struct GCInfoTrait final {
33
60
  static GCInfoIndex Index() {
34
61
  static_assert(sizeof(T), "T must be fully defined");
35
- static const RegisteredGCInfoIndex registered_index(
36
- FinalizerTrait<T>::kCallback, TraceTrait<T>::Trace,
37
- std::is_polymorphic<T>::value);
38
- return registered_index.GetIndex();
62
+ static std::atomic<GCInfoIndex>
63
+ registered_index; // Uses zero initialization.
64
+ const GCInfoIndex index = registered_index.load(std::memory_order_acquire);
65
+ return index ? index
66
+ : EnsureGCInfoIndex(
67
+ registered_index, FinalizerTrait<T>::kCallback,
68
+ TraceTrait<T>::Trace, NameTrait<T>::GetName,
69
+ std::is_polymorphic<T>::value);
39
70
  }
40
71
  };
41
72
 
@@ -0,0 +1,111 @@
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_NAME_TRAIT_H_
6
+ #define INCLUDE_CPPGC_INTERNAL_NAME_TRAIT_H_
7
+
8
+ #include <cstddef>
9
+
10
+ #include "cppgc/name-provider.h"
11
+ #include "v8config.h" // NOLINT(build/include_directory)
12
+
13
+ namespace cppgc {
14
+ namespace internal {
15
+
16
+ #if CPPGC_SUPPORTS_OBJECT_NAMES && defined(__clang__)
17
+ #define CPPGC_SUPPORTS_COMPILE_TIME_TYPENAME 1
18
+
19
+ // Provides constexpr c-string storage for a name of fixed |Size| characters.
20
+ // Automatically appends terminating 0 byte.
21
+ template <size_t Size>
22
+ struct NameBuffer {
23
+ char name[Size + 1]{};
24
+
25
+ static constexpr NameBuffer FromCString(const char* str) {
26
+ NameBuffer result;
27
+ for (size_t i = 0; i < Size; ++i) result.name[i] = str[i];
28
+ result.name[Size] = 0;
29
+ return result;
30
+ }
31
+ };
32
+
33
+ template <typename T>
34
+ const char* GetTypename() {
35
+ static constexpr char kSelfPrefix[] =
36
+ "const char *cppgc::internal::GetTypename() [T =";
37
+ static_assert(__builtin_strncmp(__PRETTY_FUNCTION__, kSelfPrefix,
38
+ sizeof(kSelfPrefix) - 1) == 0,
39
+ "The prefix must match");
40
+ static constexpr const char* kTypenameStart =
41
+ __PRETTY_FUNCTION__ + sizeof(kSelfPrefix);
42
+ static constexpr size_t kTypenameSize =
43
+ __builtin_strlen(__PRETTY_FUNCTION__) - sizeof(kSelfPrefix) - 1;
44
+ // NameBuffer is an indirection that is needed to make sure that only a
45
+ // substring of __PRETTY_FUNCTION__ gets materialized in the binary.
46
+ static constexpr auto buffer =
47
+ NameBuffer<kTypenameSize>::FromCString(kTypenameStart);
48
+ return buffer.name;
49
+ }
50
+
51
+ #else
52
+ #define CPPGC_SUPPORTS_COMPILE_TIME_TYPENAME 0
53
+ #endif
54
+
55
+ struct HeapObjectName {
56
+ const char* value;
57
+ bool name_was_hidden;
58
+ };
59
+
60
+ class V8_EXPORT NameTraitBase {
61
+ protected:
62
+ static HeapObjectName GetNameFromTypeSignature(const char*);
63
+ };
64
+
65
+ // Trait that specifies how the garbage collector retrieves the name for a
66
+ // given object.
67
+ template <typename T>
68
+ class NameTrait final : public NameTraitBase {
69
+ public:
70
+ static HeapObjectName GetName(const void* obj) {
71
+ return GetNameFor(static_cast<const T*>(obj));
72
+ }
73
+
74
+ private:
75
+ static HeapObjectName GetNameFor(const NameProvider* name_provider) {
76
+ return {name_provider->GetHumanReadableName(), false};
77
+ }
78
+
79
+ static HeapObjectName GetNameFor(...) {
80
+ #if CPPGC_SUPPORTS_COMPILE_TIME_TYPENAME
81
+ return {GetTypename<T>(), false};
82
+ #elif CPPGC_SUPPORTS_OBJECT_NAMES
83
+
84
+ #if defined(V8_CC_GNU)
85
+ #define PRETTY_FUNCTION_VALUE __PRETTY_FUNCTION__
86
+ #elif defined(V8_CC_MSVC)
87
+ #define PRETTY_FUNCTION_VALUE __FUNCSIG__
88
+ #else
89
+ #define PRETTY_FUNCTION_VALUE nullptr
90
+ #endif
91
+
92
+ static const HeapObjectName leaky_name =
93
+ GetNameFromTypeSignature(PRETTY_FUNCTION_VALUE);
94
+ return {leaky_name, false};
95
+
96
+ #undef PRETTY_FUNCTION_VALUE
97
+
98
+ #else // !CPPGC_SUPPORTS_OBJECT_NAMES
99
+ return {NameProvider::kHiddenName, true};
100
+ #endif // !CPPGC_SUPPORTS_OBJECT_NAMES
101
+ }
102
+ };
103
+
104
+ using NameCallback = HeapObjectName (*)(const void*);
105
+
106
+ } // namespace internal
107
+ } // namespace cppgc
108
+
109
+ #undef CPPGC_SUPPORTS_COMPILE_TIME_TYPENAME
110
+
111
+ #endif // INCLUDE_CPPGC_INTERNAL_NAME_TRAIT_H_
@@ -19,7 +19,9 @@ class Visitor;
19
19
 
20
20
  namespace internal {
21
21
 
22
- // PersistentNode represesents a variant of two states:
22
+ class CrossThreadPersistentRegion;
23
+
24
+ // PersistentNode represents a variant of two states:
23
25
  // 1) traceable node with a back pointer to the Persistent object;
24
26
  // 2) freelist entry.
25
27
  class PersistentNode final {
@@ -30,6 +32,7 @@ class PersistentNode final {
30
32
  PersistentNode& operator=(const PersistentNode&) = delete;
31
33
 
32
34
  void InitializeAsUsedNode(void* owner, TraceCallback trace) {
35
+ CPPGC_DCHECK(trace);
33
36
  owner_ = owner;
34
37
  trace_ = trace;
35
38
  }
@@ -89,24 +92,77 @@ class V8_EXPORT PersistentRegion final {
89
92
  }
90
93
  PersistentNode* node = free_list_head_;
91
94
  free_list_head_ = free_list_head_->FreeListNext();
95
+ CPPGC_DCHECK(!node->IsUsed());
92
96
  node->InitializeAsUsedNode(owner, trace);
97
+ nodes_in_use_++;
93
98
  return node;
94
99
  }
95
100
 
96
101
  void FreeNode(PersistentNode* node) {
102
+ CPPGC_DCHECK(node);
103
+ CPPGC_DCHECK(node->IsUsed());
97
104
  node->InitializeAsFreeNode(free_list_head_);
98
105
  free_list_head_ = node;
106
+ CPPGC_DCHECK(nodes_in_use_ > 0);
107
+ nodes_in_use_--;
99
108
  }
100
109
 
101
110
  void Trace(Visitor*);
102
111
 
103
112
  size_t NodesInUse() const;
104
113
 
114
+ void ClearAllUsedNodes();
115
+
105
116
  private:
106
117
  void EnsureNodeSlots();
107
118
 
108
119
  std::vector<std::unique_ptr<PersistentNodeSlots>> nodes_;
109
120
  PersistentNode* free_list_head_ = nullptr;
121
+ size_t nodes_in_use_ = 0;
122
+
123
+ friend class CrossThreadPersistentRegion;
124
+ };
125
+
126
+ // CrossThreadPersistent uses PersistentRegion but protects it using this lock
127
+ // when needed.
128
+ class V8_EXPORT PersistentRegionLock final {
129
+ public:
130
+ PersistentRegionLock();
131
+ ~PersistentRegionLock();
132
+
133
+ static void AssertLocked();
134
+ };
135
+
136
+ // Variant of PersistentRegion that checks whether the PersistentRegionLock is
137
+ // locked.
138
+ class V8_EXPORT CrossThreadPersistentRegion final {
139
+ public:
140
+ CrossThreadPersistentRegion() = default;
141
+ // Clears Persistent fields to avoid stale pointers after heap teardown.
142
+ ~CrossThreadPersistentRegion();
143
+
144
+ CrossThreadPersistentRegion(const CrossThreadPersistentRegion&) = delete;
145
+ CrossThreadPersistentRegion& operator=(const CrossThreadPersistentRegion&) =
146
+ delete;
147
+
148
+ V8_INLINE PersistentNode* AllocateNode(void* owner, TraceCallback trace) {
149
+ PersistentRegionLock::AssertLocked();
150
+ return persistent_region_.AllocateNode(owner, trace);
151
+ }
152
+
153
+ V8_INLINE void FreeNode(PersistentNode* node) {
154
+ PersistentRegionLock::AssertLocked();
155
+ persistent_region_.FreeNode(node);
156
+ }
157
+
158
+ void Trace(Visitor*);
159
+
160
+ size_t NodesInUse() const;
161
+
162
+ void ClearAllUsedNodes();
163
+
164
+ private:
165
+ PersistentRegion persistent_region_;
110
166
  };
111
167
 
112
168
  } // namespace internal