summaryrefslogtreecommitdiff
path: root/deps/v8/include/cppgc/internal
diff options
context:
space:
mode:
authorMichaël Zasso <targos@protonmail.com>2021-03-12 08:24:20 +0100
committerMichaël Zasso <targos@protonmail.com>2021-03-15 15:54:50 +0100
commit732ad99e47bae5deffa3a22d2ebe5500284106f0 (patch)
tree759a6b072accf188f03c74a84e8256fe92f1925c /deps/v8/include/cppgc/internal
parent802b3e7cf9a5074a72bec75cf1c46758b81e04b1 (diff)
downloadnode-new-732ad99e47bae5deffa3a22d2ebe5500284106f0.tar.gz
deps: update V8 to 9.0.257.11
PR-URL: https://github.com/nodejs/node/pull/37587 Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com>
Diffstat (limited to 'deps/v8/include/cppgc/internal')
-rw-r--r--deps/v8/include/cppgc/internal/caged-heap-local-data.h3
-rw-r--r--deps/v8/include/cppgc/internal/persistent-node.h8
-rw-r--r--deps/v8/include/cppgc/internal/pointer-policies.h23
-rw-r--r--deps/v8/include/cppgc/internal/process-heap.h34
-rw-r--r--deps/v8/include/cppgc/internal/write-barrier.h246
5 files changed, 207 insertions, 107 deletions
diff --git a/deps/v8/include/cppgc/internal/caged-heap-local-data.h b/deps/v8/include/cppgc/internal/caged-heap-local-data.h
index 8c42147738..1fa60b6953 100644
--- a/deps/v8/include/cppgc/internal/caged-heap-local-data.h
+++ b/deps/v8/include/cppgc/internal/caged-heap-local-data.h
@@ -10,6 +10,7 @@
#include "cppgc/internal/api-constants.h"
#include "cppgc/internal/logging.h"
#include "cppgc/platform.h"
+#include "v8config.h" // NOLINT(build/include_directory)
namespace cppgc {
namespace internal {
@@ -54,7 +55,7 @@ static_assert(sizeof(AgeTable) == 1 * api_constants::kMB,
struct CagedHeapLocalData final {
explicit CagedHeapLocalData(HeapBase* heap_base) : heap_base(heap_base) {}
- bool is_marking_in_progress = false;
+ bool is_incremental_marking_in_progress = false;
HeapBase* heap_base = nullptr;
#if defined(CPPGC_YOUNG_GENERATION)
AgeTable age_table;
diff --git a/deps/v8/include/cppgc/internal/persistent-node.h b/deps/v8/include/cppgc/internal/persistent-node.h
index 685d8a2d6a..6524f326a5 100644
--- a/deps/v8/include/cppgc/internal/persistent-node.h
+++ b/deps/v8/include/cppgc/internal/persistent-node.h
@@ -90,23 +90,29 @@ class V8_EXPORT PersistentRegion final {
PersistentNode* node = free_list_head_;
free_list_head_ = free_list_head_->FreeListNext();
node->InitializeAsUsedNode(owner, trace);
+ nodes_in_use_++;
return node;
}
void FreeNode(PersistentNode* node) {
node->InitializeAsFreeNode(free_list_head_);
free_list_head_ = node;
+ CPPGC_DCHECK(nodes_in_use_ > 0);
+ nodes_in_use_--;
}
void Trace(Visitor*);
size_t NodesInUse() const;
+ void ClearAllUsedNodes();
+
private:
void EnsureNodeSlots();
std::vector<std::unique_ptr<PersistentNodeSlots>> nodes_;
PersistentNode* free_list_head_ = nullptr;
+ size_t nodes_in_use_ = 0;
};
// CrossThreadPersistent uses PersistentRegion but protects it using this lock
@@ -115,6 +121,8 @@ class V8_EXPORT PersistentRegionLock final {
public:
PersistentRegionLock();
~PersistentRegionLock();
+
+ static void AssertLocked();
};
} // namespace internal
diff --git a/deps/v8/include/cppgc/internal/pointer-policies.h b/deps/v8/include/cppgc/internal/pointer-policies.h
index 58f2515a3d..ea86a0a705 100644
--- a/deps/v8/include/cppgc/internal/pointer-policies.h
+++ b/deps/v8/include/cppgc/internal/pointer-policies.h
@@ -105,22 +105,22 @@ using DefaultLocationPolicy = IgnoreLocationPolicy;
struct StrongPersistentPolicy {
using IsStrongPersistent = std::true_type;
- static V8_EXPORT PersistentRegion& GetPersistentRegion(void* object);
+ static V8_EXPORT PersistentRegion& GetPersistentRegion(const void* object);
};
struct WeakPersistentPolicy {
using IsStrongPersistent = std::false_type;
- static V8_EXPORT PersistentRegion& GetPersistentRegion(void* object);
+ static V8_EXPORT PersistentRegion& GetPersistentRegion(const void* object);
};
struct StrongCrossThreadPersistentPolicy {
using IsStrongPersistent = std::true_type;
- static V8_EXPORT PersistentRegion& GetPersistentRegion(void* object);
+ static V8_EXPORT PersistentRegion& GetPersistentRegion(const void* object);
};
struct WeakCrossThreadPersistentPolicy {
using IsStrongPersistent = std::false_type;
- static V8_EXPORT PersistentRegion& GetPersistentRegion(void* object);
+ static V8_EXPORT PersistentRegion& GetPersistentRegion(const void* object);
};
// Forward declarations setting up the default policies.
@@ -136,23 +136,8 @@ template <typename T, typename WeaknessTag, typename WriteBarrierPolicy,
typename CheckingPolicy = DefaultCheckingPolicy>
class BasicMember;
-// Special tag type used to denote some sentinel member. The semantics of the
-// sentinel is defined by the embedder.
-struct SentinelPointer {
- template <typename T>
- operator T*() const { // NOLINT
- static constexpr intptr_t kSentinelValue = 1;
- return reinterpret_cast<T*>(kSentinelValue);
- }
- // Hidden friends.
- friend bool operator==(SentinelPointer, SentinelPointer) { return true; }
- friend bool operator!=(SentinelPointer, SentinelPointer) { return false; }
-};
-
} // namespace internal
-constexpr internal::SentinelPointer kSentinelPointer;
-
} // namespace cppgc
#endif // INCLUDE_CPPGC_INTERNAL_POINTER_POLICIES_H_
diff --git a/deps/v8/include/cppgc/internal/process-heap.h b/deps/v8/include/cppgc/internal/process-heap.h
deleted file mode 100644
index 0f742a50a9..0000000000
--- a/deps/v8/include/cppgc/internal/process-heap.h
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright 2020 the V8 project authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef INCLUDE_CPPGC_INTERNAL_PROCESS_HEAP_H_
-#define INCLUDE_CPPGC_INTERNAL_PROCESS_HEAP_H_
-
-#include "cppgc/internal/atomic-entry-flag.h"
-#include "v8config.h" // NOLINT(build/include_directory)
-
-namespace cppgc {
-namespace internal {
-
-class V8_EXPORT ProcessHeap final {
- public:
- static void EnterIncrementalOrConcurrentMarking() {
- concurrent_marking_flag_.Enter();
- }
- static void ExitIncrementalOrConcurrentMarking() {
- concurrent_marking_flag_.Exit();
- }
-
- static bool IsAnyIncrementalOrConcurrentMarking() {
- return concurrent_marking_flag_.MightBeEntered();
- }
-
- private:
- static AtomicEntryFlag concurrent_marking_flag_;
-};
-
-} // namespace internal
-} // namespace cppgc
-
-#endif // INCLUDE_CPPGC_INTERNAL_PROCESS_HEAP_H_
diff --git a/deps/v8/include/cppgc/internal/write-barrier.h b/deps/v8/include/cppgc/internal/write-barrier.h
index e3cc4c989d..f3aaedb1b8 100644
--- a/deps/v8/include/cppgc/internal/write-barrier.h
+++ b/deps/v8/include/cppgc/internal/write-barrier.h
@@ -5,8 +5,10 @@
#ifndef INCLUDE_CPPGC_INTERNAL_WRITE_BARRIER_H_
#define INCLUDE_CPPGC_INTERNAL_WRITE_BARRIER_H_
+#include "cppgc/heap-state.h"
#include "cppgc/internal/api-constants.h"
-#include "cppgc/internal/process-heap.h"
+#include "cppgc/internal/atomic-entry-flag.h"
+#include "cppgc/sentinel-pointer.h"
#include "cppgc/trace-trait.h"
#include "v8config.h" // NOLINT(build/include_directory)
@@ -32,17 +34,17 @@ class V8_EXPORT WriteBarrier final {
};
struct Params {
+ HeapHandle* heap = nullptr;
#if V8_ENABLE_CHECKS
Type type = Type::kNone;
#endif // !V8_ENABLE_CHECKS
#if defined(CPPGC_CAGED_HEAP)
- uintptr_t start;
-
+ uintptr_t start = 0;
CagedHeapLocalData& caged_heap() const {
return *reinterpret_cast<CagedHeapLocalData*>(start);
}
- uintptr_t slot_offset;
- uintptr_t value_offset;
+ uintptr_t slot_offset = 0;
+ uintptr_t value_offset = 0;
#endif // CPPGC_CAGED_HEAP
};
@@ -55,14 +57,19 @@ class V8_EXPORT WriteBarrier final {
static V8_INLINE Type GetWriteBarrierType(const void* slot, const void* value,
Params& params);
// Returns the required write barrier for a given `slot`.
- static V8_INLINE Type GetWriteBarrierType(const void* slot, Params& params);
+ template <typename HeapHandleCallback>
+ static V8_INLINE Type GetWriteBarrierType(const void* slot, Params& params,
+ HeapHandleCallback callback);
+
+ template <typename HeapHandleCallback>
+ static V8_INLINE Type GetWriteBarrierTypeForExternallyReferencedObject(
+ const void* value, Params& params, HeapHandleCallback callback);
static V8_INLINE void DijkstraMarkingBarrier(const Params& params,
const void* object);
static V8_INLINE void DijkstraMarkingBarrierRange(
- const Params& params, HeapHandle& heap, const void* first_element,
- size_t element_size, size_t number_of_elements,
- TraceCallback trace_callback);
+ const Params& params, const void* first_element, size_t element_size,
+ size_t number_of_elements, TraceCallback trace_callback);
static V8_INLINE void SteeleMarkingBarrier(const Params& params,
const void* object);
#if defined(CPPGC_YOUNG_GENERATION)
@@ -79,6 +86,13 @@ class V8_EXPORT WriteBarrier final {
static void CheckParams(Type expected_type, const Params& params) {}
#endif // !V8_ENABLE_CHECKS
+ // The IncrementalOrConcurrentUpdater class allows cppgc internal to update
+ // |incremental_or_concurrent_marking_flag_|.
+ class IncrementalOrConcurrentMarkingFlagUpdater;
+ static bool IsAnyIncrementalOrConcurrentMarking() {
+ return incremental_or_concurrent_marking_flag_.MightBeEntered();
+ }
+
private:
WriteBarrier() = delete;
@@ -99,50 +113,52 @@ class V8_EXPORT WriteBarrier final {
static void SteeleMarkingBarrierSlowWithSentinelCheck(const void* value);
#if defined(CPPGC_YOUNG_GENERATION)
+ static CagedHeapLocalData& GetLocalData(HeapHandle&);
static void GenerationalBarrierSlow(const CagedHeapLocalData& local_data,
const AgeTable& ageTable,
const void* slot, uintptr_t value_offset);
#endif // CPPGC_YOUNG_GENERATION
+
+ static AtomicEntryFlag incremental_or_concurrent_marking_flag_;
};
+template <WriteBarrier::Type type>
+V8_INLINE WriteBarrier::Type SetAndReturnType(WriteBarrier::Params& params) {
+ if (type == WriteBarrier::Type::kNone) return WriteBarrier::Type::kNone;
+#if V8_ENABLE_CHECKS
+ params.type = type;
+#endif // !V8_ENABLE_CHECKS
+ return type;
+}
+
#if defined(CPPGC_CAGED_HEAP)
-class WriteBarrierTypeForCagedHeapPolicy final {
+class V8_EXPORT WriteBarrierTypeForCagedHeapPolicy final {
public:
- template <WriteBarrier::ValueMode value_mode>
+ template <WriteBarrier::ValueMode value_mode, typename HeapHandleCallback>
static V8_INLINE WriteBarrier::Type Get(const void* slot, const void* value,
- WriteBarrier::Params& params) {
- const bool have_caged_heap =
- value_mode == WriteBarrier::ValueMode::kValuePresent
- ? TryGetCagedHeap(slot, value, params)
- : TryGetCagedHeap(slot, slot, params);
- if (!have_caged_heap) {
+ WriteBarrier::Params& params,
+ HeapHandleCallback callback) {
+ return ValueModeDispatch<value_mode>::Get(slot, value, params, callback);
+ }
+
+ template <typename HeapHandleCallback>
+ static V8_INLINE WriteBarrier::Type GetForExternallyReferenced(
+ const void* value, WriteBarrier::Params& params, HeapHandleCallback) {
+ if (!TryGetCagedHeap(value, value, params)) {
return WriteBarrier::Type::kNone;
}
- if (V8_UNLIKELY(params.caged_heap().is_marking_in_progress)) {
-#if V8_ENABLE_CHECKS
- params.type = WriteBarrier::Type::kMarking;
-#endif // !V8_ENABLE_CHECKS
- return WriteBarrier::Type::kMarking;
- }
-#if defined(CPPGC_YOUNG_GENERATION)
- params.slot_offset = reinterpret_cast<uintptr_t>(slot) - params.start;
- if (value_mode == WriteBarrier::ValueMode::kValuePresent) {
- params.value_offset = reinterpret_cast<uintptr_t>(value) - params.start;
- } else {
- params.value_offset = 0;
+ if (V8_UNLIKELY(params.caged_heap().is_incremental_marking_in_progress)) {
+ return SetAndReturnType<WriteBarrier::Type::kMarking>(params);
}
-#if V8_ENABLE_CHECKS
- params.type = WriteBarrier::Type::kGenerational;
-#endif // !V8_ENABLE_CHECKS
- return WriteBarrier::Type::kGenerational;
-#else // !CPPGC_YOUNG_GENERATION
- return WriteBarrier::Type::kNone;
-#endif // !CPPGC_YOUNG_GENERATION
+ return SetAndReturnType<WriteBarrier::Type::kNone>(params);
}
private:
WriteBarrierTypeForCagedHeapPolicy() = delete;
+ template <WriteBarrier::ValueMode value_mode>
+ struct ValueModeDispatch;
+
static V8_INLINE bool TryGetCagedHeap(const void* slot, const void* value,
WriteBarrier::Params& params) {
params.start = reinterpret_cast<uintptr_t>(value) &
@@ -156,40 +172,165 @@ class WriteBarrierTypeForCagedHeapPolicy final {
}
return true;
}
+
+ // Returns whether marking is in progress. If marking is not in progress
+ // sets the start of the cage accordingly.
+ //
+ // TODO(chromium:1056170): Create fast path on API.
+ static bool IsMarking(const HeapHandle&, WriteBarrier::Params&);
+};
+
+template <>
+struct WriteBarrierTypeForCagedHeapPolicy::ValueModeDispatch<
+ WriteBarrier::ValueMode::kValuePresent> {
+ template <typename HeapHandleCallback>
+ static V8_INLINE WriteBarrier::Type Get(const void* slot, const void* value,
+ WriteBarrier::Params& params,
+ HeapHandleCallback) {
+ bool within_cage = TryGetCagedHeap(slot, value, params);
+ if (!within_cage) {
+ return WriteBarrier::Type::kNone;
+ }
+ if (V8_LIKELY(!params.caged_heap().is_incremental_marking_in_progress)) {
+#if defined(CPPGC_YOUNG_GENERATION)
+ params.heap = reinterpret_cast<HeapHandle*>(params.start);
+ params.slot_offset = reinterpret_cast<uintptr_t>(slot) - params.start;
+ params.value_offset = reinterpret_cast<uintptr_t>(value) - params.start;
+ return SetAndReturnType<WriteBarrier::Type::kGenerational>(params);
+#else // !CPPGC_YOUNG_GENERATION
+ return SetAndReturnType<WriteBarrier::Type::kNone>(params);
+#endif // !CPPGC_YOUNG_GENERATION
+ }
+ params.heap = reinterpret_cast<HeapHandle*>(params.start);
+ return SetAndReturnType<WriteBarrier::Type::kMarking>(params);
+ }
};
+
+template <>
+struct WriteBarrierTypeForCagedHeapPolicy::ValueModeDispatch<
+ WriteBarrier::ValueMode::kNoValuePresent> {
+ template <typename HeapHandleCallback>
+ static V8_INLINE WriteBarrier::Type Get(const void* slot, const void*,
+ WriteBarrier::Params& params,
+ HeapHandleCallback callback) {
+#if defined(CPPGC_YOUNG_GENERATION)
+ HeapHandle& handle = callback();
+ if (V8_LIKELY(!IsMarking(handle, params))) {
+ // params.start is populated by IsMarking().
+ params.heap = &handle;
+ params.slot_offset = reinterpret_cast<uintptr_t>(slot) - params.start;
+ // params.value_offset stays 0.
+ if (params.slot_offset > api_constants::kCagedHeapReservationSize) {
+ // Check if slot is on stack.
+ return SetAndReturnType<WriteBarrier::Type::kNone>(params);
+ }
+ return SetAndReturnType<WriteBarrier::Type::kGenerational>(params);
+ }
+#else // !CPPGC_YOUNG_GENERATION
+ if (V8_LIKELY(!WriteBarrier::IsAnyIncrementalOrConcurrentMarking())) {
+ return SetAndReturnType<WriteBarrier::Type::kNone>(params);
+ }
+ HeapHandle& handle = callback();
+ if (V8_UNLIKELY(!subtle::HeapState::IsMarking(handle))) {
+ return SetAndReturnType<WriteBarrier::Type::kNone>(params);
+ }
+#endif // !CPPGC_YOUNG_GENERATION
+ params.heap = &handle;
+ return SetAndReturnType<WriteBarrier::Type::kMarking>(params);
+ }
+};
+
#endif // CPPGC_CAGED_HEAP
-class WriteBarrierTypeForNonCagedHeapPolicy final {
+class V8_EXPORT WriteBarrierTypeForNonCagedHeapPolicy final {
public:
- template <WriteBarrier::ValueMode value_mode>
+ template <WriteBarrier::ValueMode value_mode, typename HeapHandleCallback>
static V8_INLINE WriteBarrier::Type Get(const void* slot, const void* value,
- WriteBarrier::Params& params) {
- WriteBarrier::Type type =
- V8_LIKELY(!ProcessHeap::IsAnyIncrementalOrConcurrentMarking())
- ? WriteBarrier::Type::kNone
- : WriteBarrier::Type::kMarking;
-#if V8_ENABLE_CHECKS
- params.type = type;
-#endif // !V8_ENABLE_CHECKS
- return type;
+ WriteBarrier::Params& params,
+ HeapHandleCallback callback) {
+ return ValueModeDispatch<value_mode>::Get(slot, value, params, callback);
+ }
+
+ template <typename HeapHandleCallback>
+ static V8_INLINE WriteBarrier::Type GetForExternallyReferenced(
+ const void* value, WriteBarrier::Params& params,
+ HeapHandleCallback callback) {
+ // The slot will never be used in `Get()` below.
+ return Get<WriteBarrier::ValueMode::kValuePresent>(nullptr, value, params,
+ callback);
}
private:
+ template <WriteBarrier::ValueMode value_mode>
+ struct ValueModeDispatch;
+
+ // TODO(chromium:1056170): Create fast path on API.
+ static bool IsMarking(const void*, HeapHandle**);
+ // TODO(chromium:1056170): Create fast path on API.
+ static bool IsMarking(HeapHandle&);
+
WriteBarrierTypeForNonCagedHeapPolicy() = delete;
};
+template <>
+struct WriteBarrierTypeForNonCagedHeapPolicy::ValueModeDispatch<
+ WriteBarrier::ValueMode::kValuePresent> {
+ template <typename HeapHandleCallback>
+ static V8_INLINE WriteBarrier::Type Get(const void*, const void* object,
+ WriteBarrier::Params& params,
+ HeapHandleCallback callback) {
+ // The following check covers nullptr as well as sentinel pointer.
+ if (object <= static_cast<void*>(kSentinelPointer)) {
+ return WriteBarrier::Type::kNone;
+ }
+ if (IsMarking(object, &params.heap)) {
+ return SetAndReturnType<WriteBarrier::Type::kMarking>(params);
+ }
+ return SetAndReturnType<WriteBarrier::Type::kNone>(params);
+ }
+};
+
+template <>
+struct WriteBarrierTypeForNonCagedHeapPolicy::ValueModeDispatch<
+ WriteBarrier::ValueMode::kNoValuePresent> {
+ template <typename HeapHandleCallback>
+ static V8_INLINE WriteBarrier::Type Get(const void*, const void*,
+ WriteBarrier::Params& params,
+ HeapHandleCallback callback) {
+ if (V8_UNLIKELY(WriteBarrier::IsAnyIncrementalOrConcurrentMarking())) {
+ HeapHandle& handle = callback();
+ if (IsMarking(handle)) {
+ params.heap = &handle;
+ return SetAndReturnType<WriteBarrier::Type::kMarking>(params);
+ }
+ }
+ return WriteBarrier::Type::kNone;
+ }
+};
+
// static
WriteBarrier::Type WriteBarrier::GetWriteBarrierType(
const void* slot, const void* value, WriteBarrier::Params& params) {
return WriteBarrierTypePolicy::Get<ValueMode::kValuePresent>(slot, value,
- params);
+ params, []() {});
}
// static
+template <typename HeapHandleCallback>
WriteBarrier::Type WriteBarrier::GetWriteBarrierType(
- const void* slot, WriteBarrier::Params& params) {
- return WriteBarrierTypePolicy::Get<ValueMode::kNoValuePresent>(slot, nullptr,
- params);
+ const void* slot, WriteBarrier::Params& params,
+ HeapHandleCallback callback) {
+ return WriteBarrierTypePolicy::Get<ValueMode::kNoValuePresent>(
+ slot, nullptr, params, callback);
+}
+
+// static
+template <typename HeapHandleCallback>
+WriteBarrier::Type
+WriteBarrier::GetWriteBarrierTypeForExternallyReferencedObject(
+ const void* value, Params& params, HeapHandleCallback callback) {
+ return WriteBarrierTypePolicy::GetForExternallyReferenced(value, params,
+ callback);
}
// static
@@ -206,13 +347,12 @@ void WriteBarrier::DijkstraMarkingBarrier(const Params& params,
// static
void WriteBarrier::DijkstraMarkingBarrierRange(const Params& params,
- HeapHandle& heap,
const void* first_element,
size_t element_size,
size_t number_of_elements,
TraceCallback trace_callback) {
CheckParams(Type::kMarking, params);
- DijkstraMarkingBarrierRangeSlow(heap, first_element, element_size,
+ DijkstraMarkingBarrierRangeSlow(*params.heap, first_element, element_size,
number_of_elements, trace_callback);
}