从master分支拉取puerts,并拉取v8制品,修改puerts插件部分UE5_5以下兼容的宏代码。保证puerts编译通过。包括
CSharpParamDefaultValueMetas.cs和ubtplugin.csproj和declarationGenerator.cpp和PropertyTranslator.cpp对UserDefinedStruct.h的引用
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
// 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_API_CONSTANTS_H_
|
||||
#define INCLUDE_CPPGC_INTERNAL_API_CONSTANTS_H_
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#include "v8config.h" // NOLINT(build/include_directory)
|
||||
|
||||
namespace cppgc {
|
||||
namespace internal {
|
||||
|
||||
// Embedders should not rely on this code!
|
||||
|
||||
// Internal constants to avoid exposing internal types on the API surface.
|
||||
namespace api_constants {
|
||||
|
||||
constexpr size_t kKB = 1024;
|
||||
constexpr size_t kMB = kKB * 1024;
|
||||
constexpr size_t kGB = kMB * 1024;
|
||||
|
||||
// Offset of the uint16_t bitfield from the payload contaning the
|
||||
// in-construction bit. This is subtracted from the payload pointer to get
|
||||
// to the right bitfield.
|
||||
static constexpr size_t kFullyConstructedBitFieldOffsetFromPayload =
|
||||
2 * sizeof(uint16_t);
|
||||
// Mask for in-construction bit.
|
||||
static constexpr uint16_t kFullyConstructedBitMask = uint16_t{1};
|
||||
|
||||
static constexpr size_t kPageSize = size_t{1} << 17;
|
||||
|
||||
static constexpr size_t kLargeObjectSizeThreshold = kPageSize / 2;
|
||||
|
||||
#if defined(CPPGC_CAGED_HEAP)
|
||||
constexpr size_t kCagedHeapReservationSize = static_cast<size_t>(4) * kGB;
|
||||
constexpr size_t kCagedHeapReservationAlignment = kCagedHeapReservationSize;
|
||||
#endif
|
||||
|
||||
} // namespace api_constants
|
||||
|
||||
} // namespace internal
|
||||
} // namespace cppgc
|
||||
|
||||
#endif // INCLUDE_CPPGC_INTERNAL_API_CONSTANTS_H_
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
// 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_ATOMIC_ENTRY_FLAG_H_
|
||||
#define INCLUDE_CPPGC_INTERNAL_ATOMIC_ENTRY_FLAG_H_
|
||||
|
||||
#include <atomic>
|
||||
|
||||
namespace cppgc {
|
||||
namespace internal {
|
||||
|
||||
// A flag which provides a fast check whether a scope may be entered on the
|
||||
// current thread, without needing to access thread-local storage or mutex. Can
|
||||
// have false positives (i.e., spuriously report that it might be entered), so
|
||||
// it is expected that this will be used in tandem with a precise check that the
|
||||
// scope is in fact entered on that thread.
|
||||
//
|
||||
// Example:
|
||||
// g_frobnicating_flag.MightBeEntered() &&
|
||||
// ThreadLocalFrobnicator().IsFrobnicating()
|
||||
//
|
||||
// Relaxed atomic operations are sufficient, since:
|
||||
// - all accesses remain atomic
|
||||
// - each thread must observe its own operations in order
|
||||
// - no thread ever exits the flag more times than it enters (if used correctly)
|
||||
// And so if a thread observes zero, it must be because it has observed an equal
|
||||
// number of exits as entries.
|
||||
class AtomicEntryFlag final {
|
||||
public:
|
||||
void Enter() { entries_.fetch_add(1, std::memory_order_relaxed); }
|
||||
void Exit() { entries_.fetch_sub(1, std::memory_order_relaxed); }
|
||||
|
||||
// Returns false only if the current thread is not between a call to Enter
|
||||
// and a call to Exit. Returns true if this thread or another thread may
|
||||
// currently be in the scope guarded by this flag.
|
||||
bool MightBeEntered() const {
|
||||
return entries_.load(std::memory_order_relaxed) != 0;
|
||||
}
|
||||
|
||||
private:
|
||||
std::atomic_int entries_{0};
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
} // namespace cppgc
|
||||
|
||||
#endif // INCLUDE_CPPGC_INTERNAL_ATOMIC_ENTRY_FLAG_H_
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
// 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_CAGED_HEAP_LOCAL_DATA_H_
|
||||
#define INCLUDE_CPPGC_INTERNAL_CAGED_HEAP_LOCAL_DATA_H_
|
||||
|
||||
#include <array>
|
||||
|
||||
#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 {
|
||||
|
||||
class HeapBase;
|
||||
|
||||
#if defined(CPPGC_YOUNG_GENERATION)
|
||||
|
||||
// AgeTable contains entries that correspond to 4KB memory regions. Each entry
|
||||
// can be in one of three states: kOld, kYoung or kUnknown.
|
||||
class AgeTable final {
|
||||
static constexpr size_t kGranularityBits = 12; // 4KiB per byte.
|
||||
|
||||
public:
|
||||
enum class Age : uint8_t { kOld, kYoung, kUnknown };
|
||||
|
||||
static constexpr size_t kEntrySizeInBytes = 1 << kGranularityBits;
|
||||
|
||||
Age& operator[](uintptr_t offset) { return table_[entry(offset)]; }
|
||||
Age operator[](uintptr_t offset) const { return table_[entry(offset)]; }
|
||||
|
||||
void Reset(PageAllocator* allocator);
|
||||
|
||||
private:
|
||||
static constexpr size_t kAgeTableSize =
|
||||
api_constants::kCagedHeapReservationSize >> kGranularityBits;
|
||||
|
||||
size_t entry(uintptr_t offset) const {
|
||||
const size_t entry = offset >> kGranularityBits;
|
||||
CPPGC_DCHECK(table_.size() > entry);
|
||||
return entry;
|
||||
}
|
||||
|
||||
std::array<Age, kAgeTableSize> table_;
|
||||
};
|
||||
|
||||
static_assert(sizeof(AgeTable) == 1 * api_constants::kMB,
|
||||
"Size of AgeTable is 1MB");
|
||||
|
||||
#endif // CPPGC_YOUNG_GENERATION
|
||||
|
||||
struct CagedHeapLocalData final {
|
||||
explicit CagedHeapLocalData(HeapBase* heap_base) : heap_base(heap_base) {}
|
||||
|
||||
bool is_incremental_marking_in_progress = false;
|
||||
HeapBase* heap_base = nullptr;
|
||||
#if defined(CPPGC_YOUNG_GENERATION)
|
||||
AgeTable age_table;
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
} // namespace cppgc
|
||||
|
||||
#endif // INCLUDE_CPPGC_INTERNAL_CAGED_HEAP_LOCAL_DATA_H_
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
// 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_COMPILER_SPECIFIC_H_
|
||||
#define INCLUDE_CPPGC_INTERNAL_COMPILER_SPECIFIC_H_
|
||||
|
||||
namespace cppgc {
|
||||
|
||||
#if defined(__has_attribute)
|
||||
#define CPPGC_HAS_ATTRIBUTE(FEATURE) __has_attribute(FEATURE)
|
||||
#else
|
||||
#define CPPGC_HAS_ATTRIBUTE(FEATURE) 0
|
||||
#endif
|
||||
|
||||
#if defined(__has_cpp_attribute)
|
||||
#define CPPGC_HAS_CPP_ATTRIBUTE(FEATURE) __has_cpp_attribute(FEATURE)
|
||||
#else
|
||||
#define CPPGC_HAS_CPP_ATTRIBUTE(FEATURE) 0
|
||||
#endif
|
||||
|
||||
// [[no_unique_address]] comes in C++20 but supported in clang with -std >=
|
||||
// c++11.
|
||||
#if CPPGC_HAS_CPP_ATTRIBUTE(no_unique_address)
|
||||
#define CPPGC_NO_UNIQUE_ADDRESS [[no_unique_address]]
|
||||
#else
|
||||
#define CPPGC_NO_UNIQUE_ADDRESS
|
||||
#endif
|
||||
|
||||
#if CPPGC_HAS_ATTRIBUTE(unused)
|
||||
#define CPPGC_UNUSED __attribute__((unused))
|
||||
#else
|
||||
#define CPPGC_UNUSED
|
||||
#endif
|
||||
|
||||
} // namespace cppgc
|
||||
|
||||
#endif // INCLUDE_CPPGC_INTERNAL_COMPILER_SPECIFIC_H_
|
||||
@@ -0,0 +1,90 @@
|
||||
// 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_FINALIZER_TRAIT_H_
|
||||
#define INCLUDE_CPPGC_INTERNAL_FINALIZER_TRAIT_H_
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
#include "cppgc/type-traits.h"
|
||||
|
||||
namespace cppgc {
|
||||
namespace internal {
|
||||
|
||||
using FinalizationCallback = void (*)(void*);
|
||||
|
||||
template <typename T, typename = void>
|
||||
struct HasFinalizeGarbageCollectedObject : std::false_type {};
|
||||
|
||||
template <typename T>
|
||||
struct HasFinalizeGarbageCollectedObject<
|
||||
T, void_t<decltype(std::declval<T>().FinalizeGarbageCollectedObject())>>
|
||||
: std::true_type {};
|
||||
|
||||
// The FinalizerTraitImpl specifies how to finalize objects.
|
||||
template <typename T, bool isFinalized>
|
||||
struct FinalizerTraitImpl;
|
||||
|
||||
template <typename T>
|
||||
struct FinalizerTraitImpl<T, true> {
|
||||
private:
|
||||
// Dispatch to custom FinalizeGarbageCollectedObject().
|
||||
struct Custom {
|
||||
static void Call(void* obj) {
|
||||
static_cast<T*>(obj)->FinalizeGarbageCollectedObject();
|
||||
}
|
||||
};
|
||||
|
||||
// Dispatch to regular destructor.
|
||||
struct Destructor {
|
||||
static void Call(void* obj) { static_cast<T*>(obj)->~T(); }
|
||||
};
|
||||
|
||||
using FinalizeImpl =
|
||||
std::conditional_t<HasFinalizeGarbageCollectedObject<T>::value, Custom,
|
||||
Destructor>;
|
||||
|
||||
public:
|
||||
static void Finalize(void* obj) {
|
||||
static_assert(sizeof(T), "T must be fully defined");
|
||||
FinalizeImpl::Call(obj);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct FinalizerTraitImpl<T, false> {
|
||||
static void Finalize(void* obj) {
|
||||
static_assert(sizeof(T), "T must be fully defined");
|
||||
}
|
||||
};
|
||||
|
||||
// The FinalizerTrait is used to determine if a type requires finalization and
|
||||
// what finalization means.
|
||||
template <typename T>
|
||||
struct FinalizerTrait {
|
||||
private:
|
||||
// Object has a finalizer if it has
|
||||
// - a custom FinalizeGarbageCollectedObject method, or
|
||||
// - a destructor.
|
||||
static constexpr bool kNonTrivialFinalizer =
|
||||
internal::HasFinalizeGarbageCollectedObject<T>::value ||
|
||||
!std::is_trivially_destructible<typename std::remove_cv<T>::type>::value;
|
||||
|
||||
static void Finalize(void* obj) {
|
||||
internal::FinalizerTraitImpl<T, kNonTrivialFinalizer>::Finalize(obj);
|
||||
}
|
||||
|
||||
public:
|
||||
// The callback used to finalize an object of type T.
|
||||
static constexpr FinalizationCallback kCallback =
|
||||
kNonTrivialFinalizer ? Finalize : nullptr;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
constexpr FinalizationCallback FinalizerTrait<T>::kCallback;
|
||||
|
||||
} // namespace internal
|
||||
} // namespace cppgc
|
||||
|
||||
#endif // INCLUDE_CPPGC_INTERNAL_FINALIZER_TRAIT_H_
|
||||
@@ -0,0 +1,76 @@
|
||||
// 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_GC_INFO_H_
|
||||
#define INCLUDE_CPPGC_INTERNAL_GC_INFO_H_
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <type_traits>
|
||||
|
||||
#include "cppgc/internal/finalizer-trait.h"
|
||||
#include "cppgc/internal/name-trait.h"
|
||||
#include "cppgc/trace-trait.h"
|
||||
#include "v8config.h" // NOLINT(build/include_directory)
|
||||
|
||||
namespace cppgc {
|
||||
namespace internal {
|
||||
|
||||
using GCInfoIndex = uint16_t;
|
||||
|
||||
// Acquires a new GC info object and returns the index. In addition, also
|
||||
// updates `registered_index` atomically.
|
||||
V8_EXPORT GCInfoIndex
|
||||
EnsureGCInfoIndex(std::atomic<GCInfoIndex>& registered_index,
|
||||
FinalizationCallback, TraceCallback, NameCallback, bool);
|
||||
|
||||
// Fold types based on finalizer behavior. Note that finalizer characteristics
|
||||
// align with trace behavior, i.e., destructors are virtual when trace methods
|
||||
// are and vice versa.
|
||||
template <typename T, typename ParentMostGarbageCollectedType>
|
||||
struct GCInfoFolding {
|
||||
static constexpr bool kHasVirtualDestructorAtBase =
|
||||
std::has_virtual_destructor<ParentMostGarbageCollectedType>::value;
|
||||
static constexpr bool kBothTypesAreTriviallyDestructible =
|
||||
std::is_trivially_destructible<ParentMostGarbageCollectedType>::value &&
|
||||
std::is_trivially_destructible<T>::value;
|
||||
static constexpr bool kHasCustomFinalizerDispatchAtBase =
|
||||
internal::HasFinalizeGarbageCollectedObject<
|
||||
ParentMostGarbageCollectedType>::value;
|
||||
#ifdef CPPGC_SUPPORTS_OBJECT_NAMES
|
||||
static constexpr bool kWantsDetailedObjectNames = true;
|
||||
#else // !CPPGC_SUPPORTS_OBJECT_NAMES
|
||||
static constexpr bool kWantsDetailedObjectNames = false;
|
||||
#endif // !CPPGC_SUPPORTS_OBJECT_NAMES
|
||||
|
||||
// Folding would regresses name resolution when deriving names from C++
|
||||
// class names as it would just folds a name to the base class name.
|
||||
using ResultType = std::conditional_t<(kHasVirtualDestructorAtBase ||
|
||||
kBothTypesAreTriviallyDestructible ||
|
||||
kHasCustomFinalizerDispatchAtBase) &&
|
||||
!kWantsDetailedObjectNames,
|
||||
ParentMostGarbageCollectedType, T>;
|
||||
};
|
||||
|
||||
// Trait determines how the garbage collector treats objects wrt. to traversing,
|
||||
// finalization, and naming.
|
||||
template <typename T>
|
||||
struct GCInfoTrait final {
|
||||
static GCInfoIndex Index() {
|
||||
static_assert(sizeof(T), "T must be fully defined");
|
||||
static std::atomic<GCInfoIndex>
|
||||
registered_index; // Uses zero initialization.
|
||||
const GCInfoIndex index = registered_index.load(std::memory_order_acquire);
|
||||
return index ? index
|
||||
: EnsureGCInfoIndex(
|
||||
registered_index, FinalizerTrait<T>::kCallback,
|
||||
TraceTrait<T>::Trace, NameTrait<T>::GetName,
|
||||
std::is_polymorphic<T>::value);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
} // namespace cppgc
|
||||
|
||||
#endif // INCLUDE_CPPGC_INTERNAL_GC_INFO_H_
|
||||
@@ -0,0 +1,50 @@
|
||||
// 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_LOGGING_H_
|
||||
#define INCLUDE_CPPGC_INTERNAL_LOGGING_H_
|
||||
|
||||
#include "cppgc/source-location.h"
|
||||
#include "v8config.h" // NOLINT(build/include_directory)
|
||||
|
||||
namespace cppgc {
|
||||
namespace internal {
|
||||
|
||||
void V8_EXPORT DCheckImpl(const char*,
|
||||
const SourceLocation& = SourceLocation::Current());
|
||||
[[noreturn]] void V8_EXPORT
|
||||
FatalImpl(const char*, const SourceLocation& = SourceLocation::Current());
|
||||
|
||||
// Used to ignore -Wunused-variable.
|
||||
template <typename>
|
||||
struct EatParams {};
|
||||
|
||||
#if DEBUG
|
||||
#define CPPGC_DCHECK_MSG(condition, message) \
|
||||
do { \
|
||||
if (V8_UNLIKELY(!(condition))) { \
|
||||
::cppgc::internal::DCheckImpl(message); \
|
||||
} \
|
||||
} while (false)
|
||||
#else
|
||||
#define CPPGC_DCHECK_MSG(condition, message) \
|
||||
(static_cast<void>(::cppgc::internal::EatParams<decltype( \
|
||||
static_cast<void>(condition), message)>{}))
|
||||
#endif
|
||||
|
||||
#define CPPGC_DCHECK(condition) CPPGC_DCHECK_MSG(condition, #condition)
|
||||
|
||||
#define CPPGC_CHECK_MSG(condition, message) \
|
||||
do { \
|
||||
if (V8_UNLIKELY(!(condition))) { \
|
||||
::cppgc::internal::FatalImpl(message); \
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
#define CPPGC_CHECK(condition) CPPGC_CHECK_MSG(condition, #condition)
|
||||
|
||||
} // namespace internal
|
||||
} // namespace cppgc
|
||||
|
||||
#endif // INCLUDE_CPPGC_INTERNAL_LOGGING_H_
|
||||
@@ -0,0 +1,111 @@
|
||||
// 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_NAME_TRAIT_H_
|
||||
#define INCLUDE_CPPGC_INTERNAL_NAME_TRAIT_H_
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#include "cppgc/name-provider.h"
|
||||
#include "v8config.h" // NOLINT(build/include_directory)
|
||||
|
||||
namespace cppgc {
|
||||
namespace internal {
|
||||
|
||||
#if CPPGC_SUPPORTS_OBJECT_NAMES && defined(__clang__)
|
||||
#define CPPGC_SUPPORTS_COMPILE_TIME_TYPENAME 1
|
||||
|
||||
// Provides constexpr c-string storage for a name of fixed |Size| characters.
|
||||
// Automatically appends terminating 0 byte.
|
||||
template <size_t Size>
|
||||
struct NameBuffer {
|
||||
char name[Size + 1]{};
|
||||
|
||||
static constexpr NameBuffer FromCString(const char* str) {
|
||||
NameBuffer result;
|
||||
for (size_t i = 0; i < Size; ++i) result.name[i] = str[i];
|
||||
result.name[Size] = 0;
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
const char* GetTypename() {
|
||||
static constexpr char kSelfPrefix[] =
|
||||
"const char *cppgc::internal::GetTypename() [T =";
|
||||
static_assert(__builtin_strncmp(__PRETTY_FUNCTION__, kSelfPrefix,
|
||||
sizeof(kSelfPrefix) - 1) == 0,
|
||||
"The prefix must match");
|
||||
static constexpr const char* kTypenameStart =
|
||||
__PRETTY_FUNCTION__ + sizeof(kSelfPrefix);
|
||||
static constexpr size_t kTypenameSize =
|
||||
__builtin_strlen(__PRETTY_FUNCTION__) - sizeof(kSelfPrefix) - 1;
|
||||
// NameBuffer is an indirection that is needed to make sure that only a
|
||||
// substring of __PRETTY_FUNCTION__ gets materialized in the binary.
|
||||
static constexpr auto buffer =
|
||||
NameBuffer<kTypenameSize>::FromCString(kTypenameStart);
|
||||
return buffer.name;
|
||||
}
|
||||
|
||||
#else
|
||||
#define CPPGC_SUPPORTS_COMPILE_TIME_TYPENAME 0
|
||||
#endif
|
||||
|
||||
struct HeapObjectName {
|
||||
const char* value;
|
||||
bool name_was_hidden;
|
||||
};
|
||||
|
||||
class V8_EXPORT NameTraitBase {
|
||||
protected:
|
||||
static HeapObjectName GetNameFromTypeSignature(const char*);
|
||||
};
|
||||
|
||||
// Trait that specifies how the garbage collector retrieves the name for a
|
||||
// given object.
|
||||
template <typename T>
|
||||
class NameTrait final : public NameTraitBase {
|
||||
public:
|
||||
static HeapObjectName GetName(const void* obj) {
|
||||
return GetNameFor(static_cast<const T*>(obj));
|
||||
}
|
||||
|
||||
private:
|
||||
static HeapObjectName GetNameFor(const NameProvider* name_provider) {
|
||||
return {name_provider->GetHumanReadableName(), false};
|
||||
}
|
||||
|
||||
static HeapObjectName GetNameFor(...) {
|
||||
#if CPPGC_SUPPORTS_COMPILE_TIME_TYPENAME
|
||||
return {GetTypename<T>(), false};
|
||||
#elif CPPGC_SUPPORTS_OBJECT_NAMES
|
||||
|
||||
#if defined(V8_CC_GNU)
|
||||
#define PRETTY_FUNCTION_VALUE __PRETTY_FUNCTION__
|
||||
#elif defined(V8_CC_MSVC)
|
||||
#define PRETTY_FUNCTION_VALUE __FUNCSIG__
|
||||
#else
|
||||
#define PRETTY_FUNCTION_VALUE nullptr
|
||||
#endif
|
||||
|
||||
static const HeapObjectName leaky_name =
|
||||
GetNameFromTypeSignature(PRETTY_FUNCTION_VALUE);
|
||||
return {leaky_name, false};
|
||||
|
||||
#undef PRETTY_FUNCTION_VALUE
|
||||
|
||||
#else // !CPPGC_SUPPORTS_OBJECT_NAMES
|
||||
return {NameProvider::kHiddenName, true};
|
||||
#endif // !CPPGC_SUPPORTS_OBJECT_NAMES
|
||||
}
|
||||
};
|
||||
|
||||
using NameCallback = HeapObjectName (*)(const void*);
|
||||
|
||||
} // namespace internal
|
||||
} // namespace cppgc
|
||||
|
||||
#undef CPPGC_SUPPORTS_COMPILE_TIME_TYPENAME
|
||||
|
||||
#endif // INCLUDE_CPPGC_INTERNAL_NAME_TRAIT_H_
|
||||
+172
@@ -0,0 +1,172 @@
|
||||
// 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_PERSISTENT_NODE_H_
|
||||
#define INCLUDE_CPPGC_INTERNAL_PERSISTENT_NODE_H_
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "cppgc/internal/logging.h"
|
||||
#include "cppgc/trace-trait.h"
|
||||
#include "v8config.h" // NOLINT(build/include_directory)
|
||||
|
||||
namespace cppgc {
|
||||
|
||||
class Visitor;
|
||||
|
||||
namespace internal {
|
||||
|
||||
class CrossThreadPersistentRegion;
|
||||
|
||||
// PersistentNode represents a variant of two states:
|
||||
// 1) traceable node with a back pointer to the Persistent object;
|
||||
// 2) freelist entry.
|
||||
class PersistentNode final {
|
||||
public:
|
||||
PersistentNode() = default;
|
||||
|
||||
PersistentNode(const PersistentNode&) = delete;
|
||||
PersistentNode& operator=(const PersistentNode&) = delete;
|
||||
|
||||
void InitializeAsUsedNode(void* owner, TraceCallback trace) {
|
||||
CPPGC_DCHECK(trace);
|
||||
owner_ = owner;
|
||||
trace_ = trace;
|
||||
}
|
||||
|
||||
void InitializeAsFreeNode(PersistentNode* next) {
|
||||
next_ = next;
|
||||
trace_ = nullptr;
|
||||
}
|
||||
|
||||
void UpdateOwner(void* owner) {
|
||||
CPPGC_DCHECK(IsUsed());
|
||||
owner_ = owner;
|
||||
}
|
||||
|
||||
PersistentNode* FreeListNext() const {
|
||||
CPPGC_DCHECK(!IsUsed());
|
||||
return next_;
|
||||
}
|
||||
|
||||
void Trace(Visitor* visitor) const {
|
||||
CPPGC_DCHECK(IsUsed());
|
||||
trace_(visitor, owner_);
|
||||
}
|
||||
|
||||
bool IsUsed() const { return trace_; }
|
||||
|
||||
void* owner() const {
|
||||
CPPGC_DCHECK(IsUsed());
|
||||
return owner_;
|
||||
}
|
||||
|
||||
private:
|
||||
// PersistentNode acts as a designated union:
|
||||
// If trace_ != nullptr, owner_ points to the corresponding Persistent handle.
|
||||
// Otherwise, next_ points to the next freed PersistentNode.
|
||||
union {
|
||||
void* owner_ = nullptr;
|
||||
PersistentNode* next_;
|
||||
};
|
||||
TraceCallback trace_ = nullptr;
|
||||
};
|
||||
|
||||
class V8_EXPORT PersistentRegion {
|
||||
using PersistentNodeSlots = std::array<PersistentNode, 256u>;
|
||||
|
||||
public:
|
||||
PersistentRegion() = default;
|
||||
// Clears Persistent fields to avoid stale pointers after heap teardown.
|
||||
~PersistentRegion();
|
||||
|
||||
PersistentRegion(const PersistentRegion&) = delete;
|
||||
PersistentRegion& operator=(const PersistentRegion&) = delete;
|
||||
|
||||
PersistentNode* AllocateNode(void* owner, TraceCallback trace) {
|
||||
if (!free_list_head_) {
|
||||
EnsureNodeSlots();
|
||||
}
|
||||
PersistentNode* node = free_list_head_;
|
||||
free_list_head_ = free_list_head_->FreeListNext();
|
||||
CPPGC_DCHECK(!node->IsUsed());
|
||||
node->InitializeAsUsedNode(owner, trace);
|
||||
nodes_in_use_++;
|
||||
return node;
|
||||
}
|
||||
|
||||
void FreeNode(PersistentNode* node) {
|
||||
CPPGC_DCHECK(node);
|
||||
CPPGC_DCHECK(node->IsUsed());
|
||||
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();
|
||||
|
||||
template <typename PersistentBaseClass>
|
||||
void ClearAllUsedNodes();
|
||||
|
||||
std::vector<std::unique_ptr<PersistentNodeSlots>> nodes_;
|
||||
PersistentNode* free_list_head_ = nullptr;
|
||||
size_t nodes_in_use_ = 0;
|
||||
|
||||
friend class CrossThreadPersistentRegion;
|
||||
};
|
||||
|
||||
// CrossThreadPersistent uses PersistentRegion but protects it using this lock
|
||||
// when needed.
|
||||
class V8_EXPORT PersistentRegionLock final {
|
||||
public:
|
||||
PersistentRegionLock();
|
||||
~PersistentRegionLock();
|
||||
|
||||
static void AssertLocked();
|
||||
};
|
||||
|
||||
// Variant of PersistentRegion that checks whether the PersistentRegionLock is
|
||||
// locked.
|
||||
class V8_EXPORT CrossThreadPersistentRegion final : protected PersistentRegion {
|
||||
public:
|
||||
CrossThreadPersistentRegion() = default;
|
||||
// Clears Persistent fields to avoid stale pointers after heap teardown.
|
||||
~CrossThreadPersistentRegion();
|
||||
|
||||
CrossThreadPersistentRegion(const CrossThreadPersistentRegion&) = delete;
|
||||
CrossThreadPersistentRegion& operator=(const CrossThreadPersistentRegion&) =
|
||||
delete;
|
||||
|
||||
V8_INLINE PersistentNode* AllocateNode(void* owner, TraceCallback trace) {
|
||||
PersistentRegionLock::AssertLocked();
|
||||
return PersistentRegion::AllocateNode(owner, trace);
|
||||
}
|
||||
|
||||
V8_INLINE void FreeNode(PersistentNode* node) {
|
||||
PersistentRegionLock::AssertLocked();
|
||||
PersistentRegion::FreeNode(node);
|
||||
}
|
||||
|
||||
void Trace(Visitor*);
|
||||
|
||||
size_t NodesInUse() const;
|
||||
|
||||
void ClearAllUsedNodes();
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
} // namespace cppgc
|
||||
|
||||
#endif // INCLUDE_CPPGC_INTERNAL_PERSISTENT_NODE_H_
|
||||
+175
@@ -0,0 +1,175 @@
|
||||
// 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_POINTER_POLICIES_H_
|
||||
#define INCLUDE_CPPGC_INTERNAL_POINTER_POLICIES_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <type_traits>
|
||||
|
||||
#include "cppgc/internal/write-barrier.h"
|
||||
#include "cppgc/sentinel-pointer.h"
|
||||
#include "cppgc/source-location.h"
|
||||
#include "cppgc/type-traits.h"
|
||||
#include "v8config.h" // NOLINT(build/include_directory)
|
||||
|
||||
namespace cppgc {
|
||||
namespace internal {
|
||||
|
||||
class HeapBase;
|
||||
class PersistentRegion;
|
||||
class CrossThreadPersistentRegion;
|
||||
|
||||
// Tags to distinguish between strong and weak member types.
|
||||
class StrongMemberTag;
|
||||
class WeakMemberTag;
|
||||
class UntracedMemberTag;
|
||||
|
||||
struct DijkstraWriteBarrierPolicy {
|
||||
static void InitializingBarrier(const void*, const void*) {
|
||||
// Since in initializing writes the source object is always white, having no
|
||||
// barrier doesn't break the tri-color invariant.
|
||||
}
|
||||
static void AssigningBarrier(const void* slot, const void* value) {
|
||||
WriteBarrier::Params params;
|
||||
switch (WriteBarrier::GetWriteBarrierType(slot, value, params)) {
|
||||
case WriteBarrier::Type::kGenerational:
|
||||
WriteBarrier::GenerationalBarrier(params, slot);
|
||||
break;
|
||||
case WriteBarrier::Type::kMarking:
|
||||
WriteBarrier::DijkstraMarkingBarrier(params, value);
|
||||
break;
|
||||
case WriteBarrier::Type::kNone:
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct NoWriteBarrierPolicy {
|
||||
static void InitializingBarrier(const void*, const void*) {}
|
||||
static void AssigningBarrier(const void*, const void*) {}
|
||||
};
|
||||
|
||||
class V8_EXPORT EnabledCheckingPolicy {
|
||||
protected:
|
||||
template <typename T>
|
||||
void CheckPointer(const T* ptr) {
|
||||
if (!ptr || (kSentinelPointer == ptr)) return;
|
||||
|
||||
CheckPointersImplTrampoline<T>::Call(this, ptr);
|
||||
}
|
||||
|
||||
private:
|
||||
void CheckPointerImpl(const void* ptr, bool points_to_payload);
|
||||
|
||||
template <typename T, bool = IsCompleteV<T>>
|
||||
struct CheckPointersImplTrampoline {
|
||||
static void Call(EnabledCheckingPolicy* policy, const T* ptr) {
|
||||
policy->CheckPointerImpl(ptr, false);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct CheckPointersImplTrampoline<T, true> {
|
||||
static void Call(EnabledCheckingPolicy* policy, const T* ptr) {
|
||||
policy->CheckPointerImpl(ptr, IsGarbageCollectedTypeV<T>);
|
||||
}
|
||||
};
|
||||
|
||||
const HeapBase* heap_ = nullptr;
|
||||
};
|
||||
|
||||
class DisabledCheckingPolicy {
|
||||
protected:
|
||||
void CheckPointer(const void*) {}
|
||||
};
|
||||
|
||||
#if V8_ENABLE_CHECKS
|
||||
using DefaultMemberCheckingPolicy = EnabledCheckingPolicy;
|
||||
using DefaultPersistentCheckingPolicy = EnabledCheckingPolicy;
|
||||
#else
|
||||
using DefaultMemberCheckingPolicy = DisabledCheckingPolicy;
|
||||
using DefaultPersistentCheckingPolicy = DisabledCheckingPolicy;
|
||||
#endif
|
||||
// For CT(W)P neither marking information (for value), nor objectstart bitmap
|
||||
// (for slot) are guaranteed to be present because there's no synchonization
|
||||
// between heaps after marking.
|
||||
using DefaultCrossThreadPersistentCheckingPolicy = DisabledCheckingPolicy;
|
||||
|
||||
class KeepLocationPolicy {
|
||||
public:
|
||||
constexpr const SourceLocation& Location() const { return location_; }
|
||||
|
||||
protected:
|
||||
constexpr KeepLocationPolicy() = default;
|
||||
constexpr explicit KeepLocationPolicy(const SourceLocation& location)
|
||||
: location_(location) {}
|
||||
|
||||
// KeepLocationPolicy must not copy underlying source locations.
|
||||
KeepLocationPolicy(const KeepLocationPolicy&) = delete;
|
||||
KeepLocationPolicy& operator=(const KeepLocationPolicy&) = delete;
|
||||
|
||||
// Location of the original moved from object should be preserved.
|
||||
KeepLocationPolicy(KeepLocationPolicy&&) = default;
|
||||
KeepLocationPolicy& operator=(KeepLocationPolicy&&) = default;
|
||||
|
||||
private:
|
||||
SourceLocation location_;
|
||||
};
|
||||
|
||||
class IgnoreLocationPolicy {
|
||||
public:
|
||||
constexpr SourceLocation Location() const { return {}; }
|
||||
|
||||
protected:
|
||||
constexpr IgnoreLocationPolicy() = default;
|
||||
constexpr explicit IgnoreLocationPolicy(const SourceLocation&) {}
|
||||
};
|
||||
|
||||
#if CPPGC_SUPPORTS_OBJECT_NAMES
|
||||
using DefaultLocationPolicy = KeepLocationPolicy;
|
||||
#else
|
||||
using DefaultLocationPolicy = IgnoreLocationPolicy;
|
||||
#endif
|
||||
|
||||
struct StrongPersistentPolicy {
|
||||
using IsStrongPersistent = std::true_type;
|
||||
static V8_EXPORT PersistentRegion& GetPersistentRegion(const void* object);
|
||||
};
|
||||
|
||||
struct WeakPersistentPolicy {
|
||||
using IsStrongPersistent = std::false_type;
|
||||
static V8_EXPORT PersistentRegion& GetPersistentRegion(const void* object);
|
||||
};
|
||||
|
||||
struct StrongCrossThreadPersistentPolicy {
|
||||
using IsStrongPersistent = std::true_type;
|
||||
static V8_EXPORT CrossThreadPersistentRegion& GetPersistentRegion(
|
||||
const void* object);
|
||||
};
|
||||
|
||||
struct WeakCrossThreadPersistentPolicy {
|
||||
using IsStrongPersistent = std::false_type;
|
||||
static V8_EXPORT CrossThreadPersistentRegion& GetPersistentRegion(
|
||||
const void* object);
|
||||
};
|
||||
|
||||
// Forward declarations setting up the default policies.
|
||||
template <typename T, typename WeaknessPolicy,
|
||||
typename LocationPolicy = DefaultLocationPolicy,
|
||||
typename CheckingPolicy = DefaultCrossThreadPersistentCheckingPolicy>
|
||||
class BasicCrossThreadPersistent;
|
||||
template <typename T, typename WeaknessPolicy,
|
||||
typename LocationPolicy = DefaultLocationPolicy,
|
||||
typename CheckingPolicy = DefaultPersistentCheckingPolicy>
|
||||
class BasicPersistent;
|
||||
template <typename T, typename WeaknessTag, typename WriteBarrierPolicy,
|
||||
typename CheckingPolicy = DefaultMemberCheckingPolicy>
|
||||
class BasicMember;
|
||||
|
||||
} // namespace internal
|
||||
|
||||
} // namespace cppgc
|
||||
|
||||
#endif // INCLUDE_CPPGC_INTERNAL_POINTER_POLICIES_H_
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
// 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_PREFINALIZER_HANDLER_H_
|
||||
#define INCLUDE_CPPGC_INTERNAL_PREFINALIZER_HANDLER_H_
|
||||
|
||||
#include "cppgc/heap.h"
|
||||
#include "cppgc/liveness-broker.h"
|
||||
|
||||
namespace cppgc {
|
||||
namespace internal {
|
||||
|
||||
class V8_EXPORT PreFinalizerRegistrationDispatcher final {
|
||||
public:
|
||||
using PreFinalizerCallback = bool (*)(const LivenessBroker&, void*);
|
||||
struct PreFinalizer {
|
||||
void* object;
|
||||
PreFinalizerCallback callback;
|
||||
|
||||
bool operator==(const PreFinalizer& other) const;
|
||||
};
|
||||
|
||||
static void RegisterPrefinalizer(PreFinalizer pre_finalizer);
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
} // namespace cppgc
|
||||
|
||||
#endif // INCLUDE_CPPGC_INTERNAL_PREFINALIZER_HANDLER_H_
|
||||
@@ -0,0 +1,433 @@
|
||||
// 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_WRITE_BARRIER_H_
|
||||
#define INCLUDE_CPPGC_INTERNAL_WRITE_BARRIER_H_
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#include "cppgc/heap-state.h"
|
||||
#include "cppgc/internal/api-constants.h"
|
||||
#include "cppgc/internal/atomic-entry-flag.h"
|
||||
#include "cppgc/platform.h"
|
||||
#include "cppgc/sentinel-pointer.h"
|
||||
#include "cppgc/trace-trait.h"
|
||||
#include "v8config.h" // NOLINT(build/include_directory)
|
||||
|
||||
#if defined(CPPGC_CAGED_HEAP)
|
||||
#include "cppgc/internal/caged-heap-local-data.h"
|
||||
#endif
|
||||
|
||||
namespace cppgc {
|
||||
|
||||
class HeapHandle;
|
||||
|
||||
namespace internal {
|
||||
|
||||
#if defined(CPPGC_CAGED_HEAP)
|
||||
class WriteBarrierTypeForCagedHeapPolicy;
|
||||
#else // !CPPGC_CAGED_HEAP
|
||||
class WriteBarrierTypeForNonCagedHeapPolicy;
|
||||
#endif // !CPPGC_CAGED_HEAP
|
||||
|
||||
class V8_EXPORT WriteBarrier final {
|
||||
public:
|
||||
enum class Type : uint8_t {
|
||||
kNone,
|
||||
kMarking,
|
||||
kGenerational,
|
||||
};
|
||||
|
||||
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 = 0;
|
||||
CagedHeapLocalData& caged_heap() const {
|
||||
return *reinterpret_cast<CagedHeapLocalData*>(start);
|
||||
}
|
||||
uintptr_t slot_offset = 0;
|
||||
uintptr_t value_offset = 0;
|
||||
#endif // CPPGC_CAGED_HEAP
|
||||
};
|
||||
|
||||
enum class ValueMode {
|
||||
kValuePresent,
|
||||
kNoValuePresent,
|
||||
};
|
||||
|
||||
// Returns the required write barrier for a given `slot` and `value`.
|
||||
static V8_INLINE Type GetWriteBarrierType(const void* slot, const void* value,
|
||||
Params& params);
|
||||
// Returns the required write barrier for a given `slot`.
|
||||
template <typename HeapHandleCallback>
|
||||
static V8_INLINE Type GetWriteBarrierType(const void* slot, Params& params,
|
||||
HeapHandleCallback callback);
|
||||
// Returns the required write barrier for a given `value`.
|
||||
static V8_INLINE Type GetWriteBarrierType(const void* value, Params& params);
|
||||
|
||||
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, 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)
|
||||
static V8_INLINE void GenerationalBarrier(const Params& params,
|
||||
const void* slot);
|
||||
#else // !CPPGC_YOUNG_GENERATION
|
||||
static V8_INLINE void GenerationalBarrier(const Params& params,
|
||||
const void* slot) {}
|
||||
#endif // CPPGC_YOUNG_GENERATION
|
||||
|
||||
#if V8_ENABLE_CHECKS
|
||||
static void CheckParams(Type expected_type, const Params& params);
|
||||
#else // !V8_ENABLE_CHECKS
|
||||
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;
|
||||
|
||||
#if defined(CPPGC_CAGED_HEAP)
|
||||
using WriteBarrierTypePolicy = WriteBarrierTypeForCagedHeapPolicy;
|
||||
#else // !CPPGC_CAGED_HEAP
|
||||
using WriteBarrierTypePolicy = WriteBarrierTypeForNonCagedHeapPolicy;
|
||||
#endif // !CPPGC_CAGED_HEAP
|
||||
|
||||
static void DijkstraMarkingBarrierSlow(const void* value);
|
||||
static void DijkstraMarkingBarrierSlowWithSentinelCheck(const void* value);
|
||||
static void DijkstraMarkingBarrierRangeSlow(HeapHandle& heap_handle,
|
||||
const void* first_element,
|
||||
size_t element_size,
|
||||
size_t number_of_elements,
|
||||
TraceCallback trace_callback);
|
||||
static void SteeleMarkingBarrierSlow(const void* value);
|
||||
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 V8_EXPORT WriteBarrierTypeForCagedHeapPolicy final {
|
||||
public:
|
||||
template <WriteBarrier::ValueMode value_mode, typename HeapHandleCallback>
|
||||
static V8_INLINE WriteBarrier::Type Get(const void* slot, const void* value,
|
||||
WriteBarrier::Params& params,
|
||||
HeapHandleCallback callback) {
|
||||
return ValueModeDispatch<value_mode>::Get(slot, value, params, callback);
|
||||
}
|
||||
|
||||
template <WriteBarrier::ValueMode value_mode, typename HeapHandleCallback>
|
||||
static V8_INLINE WriteBarrier::Type Get(const void* value,
|
||||
WriteBarrier::Params& params,
|
||||
HeapHandleCallback callback) {
|
||||
return GetNoSlot(value, params, callback);
|
||||
}
|
||||
|
||||
template <typename HeapHandleCallback>
|
||||
static V8_INLINE WriteBarrier::Type GetForExternallyReferenced(
|
||||
const void* value, WriteBarrier::Params& params,
|
||||
HeapHandleCallback callback) {
|
||||
return GetNoSlot(value, params, callback);
|
||||
}
|
||||
|
||||
private:
|
||||
WriteBarrierTypeForCagedHeapPolicy() = delete;
|
||||
|
||||
template <typename HeapHandleCallback>
|
||||
static V8_INLINE WriteBarrier::Type GetNoSlot(const void* value,
|
||||
WriteBarrier::Params& params,
|
||||
HeapHandleCallback) {
|
||||
if (!TryGetCagedHeap(value, value, params)) {
|
||||
return WriteBarrier::Type::kNone;
|
||||
}
|
||||
if (V8_UNLIKELY(params.caged_heap().is_incremental_marking_in_progress)) {
|
||||
return SetAndReturnType<WriteBarrier::Type::kMarking>(params);
|
||||
}
|
||||
return SetAndReturnType<WriteBarrier::Type::kNone>(params);
|
||||
}
|
||||
|
||||
template <WriteBarrier::ValueMode value_mode>
|
||||
struct ValueModeDispatch;
|
||||
|
||||
static V8_INLINE bool TryGetCagedHeap(const void* slot, const void* value,
|
||||
WriteBarrier::Params& params) {
|
||||
// TODO(chromium:1056170): Check if the null check can be folded in with
|
||||
// the rest of the write barrier.
|
||||
if (!value) return false;
|
||||
params.start = reinterpret_cast<uintptr_t>(value) &
|
||||
~(api_constants::kCagedHeapReservationAlignment - 1);
|
||||
const uintptr_t slot_offset =
|
||||
reinterpret_cast<uintptr_t>(slot) - params.start;
|
||||
if (slot_offset > api_constants::kCagedHeapReservationSize) {
|
||||
// Check if slot is on stack or value is sentinel or nullptr. This relies
|
||||
// on the fact that kSentinelPointer is encoded as 0x1.
|
||||
return false;
|
||||
}
|
||||
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 V8_EXPORT WriteBarrierTypeForNonCagedHeapPolicy final {
|
||||
public:
|
||||
template <WriteBarrier::ValueMode value_mode, typename HeapHandleCallback>
|
||||
static V8_INLINE WriteBarrier::Type Get(const void* slot, const void* value,
|
||||
WriteBarrier::Params& params,
|
||||
HeapHandleCallback callback) {
|
||||
return ValueModeDispatch<value_mode>::Get(slot, value, params, callback);
|
||||
}
|
||||
|
||||
template <WriteBarrier::ValueMode value_mode, typename HeapHandleCallback>
|
||||
static V8_INLINE WriteBarrier::Type Get(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);
|
||||
}
|
||||
|
||||
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, ¶ms.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, []() {});
|
||||
}
|
||||
|
||||
// static
|
||||
template <typename HeapHandleCallback>
|
||||
WriteBarrier::Type WriteBarrier::GetWriteBarrierType(
|
||||
const void* slot, WriteBarrier::Params& params,
|
||||
HeapHandleCallback callback) {
|
||||
return WriteBarrierTypePolicy::Get<ValueMode::kNoValuePresent>(
|
||||
slot, nullptr, params, callback);
|
||||
}
|
||||
|
||||
// static
|
||||
WriteBarrier::Type WriteBarrier::GetWriteBarrierType(
|
||||
const void* value, WriteBarrier::Params& params) {
|
||||
return WriteBarrierTypePolicy::Get<ValueMode::kValuePresent>(value, params,
|
||||
[]() {});
|
||||
}
|
||||
|
||||
// static
|
||||
template <typename HeapHandleCallback>
|
||||
WriteBarrier::Type
|
||||
WriteBarrier::GetWriteBarrierTypeForExternallyReferencedObject(
|
||||
const void* value, Params& params, HeapHandleCallback callback) {
|
||||
return WriteBarrierTypePolicy::GetForExternallyReferenced(value, params,
|
||||
callback);
|
||||
}
|
||||
|
||||
// static
|
||||
void WriteBarrier::DijkstraMarkingBarrier(const Params& params,
|
||||
const void* object) {
|
||||
CheckParams(Type::kMarking, params);
|
||||
#if defined(CPPGC_CAGED_HEAP)
|
||||
// Caged heap already filters out sentinels.
|
||||
DijkstraMarkingBarrierSlow(object);
|
||||
#else // !CPPGC_CAGED_HEAP
|
||||
DijkstraMarkingBarrierSlowWithSentinelCheck(object);
|
||||
#endif // !CPPGC_CAGED_HEAP
|
||||
}
|
||||
|
||||
// static
|
||||
void WriteBarrier::DijkstraMarkingBarrierRange(const Params& params,
|
||||
const void* first_element,
|
||||
size_t element_size,
|
||||
size_t number_of_elements,
|
||||
TraceCallback trace_callback) {
|
||||
CheckParams(Type::kMarking, params);
|
||||
DijkstraMarkingBarrierRangeSlow(*params.heap, first_element, element_size,
|
||||
number_of_elements, trace_callback);
|
||||
}
|
||||
|
||||
// static
|
||||
void WriteBarrier::SteeleMarkingBarrier(const Params& params,
|
||||
const void* object) {
|
||||
CheckParams(Type::kMarking, params);
|
||||
#if defined(CPPGC_CAGED_HEAP)
|
||||
// Caged heap already filters out sentinels.
|
||||
SteeleMarkingBarrierSlow(object);
|
||||
#else // !CPPGC_CAGED_HEAP
|
||||
SteeleMarkingBarrierSlowWithSentinelCheck(object);
|
||||
#endif // !CPPGC_CAGED_HEAP
|
||||
}
|
||||
|
||||
#if defined(CPPGC_YOUNG_GENERATION)
|
||||
// static
|
||||
void WriteBarrier::GenerationalBarrier(const Params& params, const void* slot) {
|
||||
CheckParams(Type::kGenerational, params);
|
||||
|
||||
const CagedHeapLocalData& local_data = params.caged_heap();
|
||||
const AgeTable& age_table = local_data.age_table;
|
||||
|
||||
// Bail out if the slot is in young generation.
|
||||
if (V8_LIKELY(age_table[params.slot_offset] == AgeTable::Age::kYoung)) return;
|
||||
|
||||
GenerationalBarrierSlow(local_data, age_table, slot, params.value_offset);
|
||||
}
|
||||
|
||||
#endif // !CPPGC_YOUNG_GENERATION
|
||||
|
||||
} // namespace internal
|
||||
} // namespace cppgc
|
||||
|
||||
#endif // INCLUDE_CPPGC_INTERNAL_WRITE_BARRIER_H_
|
||||
Reference in New Issue
Block a user