Commit 9d01bb7f authored by Michael Lippautz's avatar Michael Lippautz Committed by Commit Bot

bindings: Implement TraceWrapperV8Reference without destructor

The previous implementation of using a trait had the problem of not being able
to override already instantiated templates. Rely on a different type
"v8::TracedReference" instead that does not come with a destructor.

Bug: 995684
Change-Id: Ia6d5ae1964b47e7460f76aa5df154f1b4d0c63d3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1848011
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarYuki Shiino <yukishiino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704233}
parent d36575d5
...@@ -173,8 +173,9 @@ class GC_PLUGIN_IGNORE( ...@@ -173,8 +173,9 @@ class GC_PLUGIN_IGNORE(
uint16_t class_id) override; uint16_t class_id) override;
// v8::EmbedderHeapTracer::TracedGlobalHandleVisitor override. // v8::EmbedderHeapTracer::TracedGlobalHandleVisitor override.
void VisitTracedGlobalHandle( void VisitTracedReference(
const v8::TracedGlobal<v8::Value>& value) override; const v8::TracedReference<v8::Value>& value) override;
void VisitTracedGlobalHandle(const v8::TracedGlobal<v8::Value>&) override;
// Visitor overrides. // Visitor overrides.
void VisitRoot(void*, TraceDescriptor, const base::Location&) final; void VisitRoot(void*, TraceDescriptor, const base::Location&) final;
...@@ -508,8 +509,8 @@ void V8EmbedderGraphBuilder::VisitPersistentHandleInternal( ...@@ -508,8 +509,8 @@ void V8EmbedderGraphBuilder::VisitPersistentHandleInternal(
} }
} }
void V8EmbedderGraphBuilder::VisitTracedGlobalHandle( void V8EmbedderGraphBuilder::VisitTracedReference(
const v8::TracedGlobal<v8::Value>& value) { const v8::TracedReference<v8::Value>& value) {
const uint16_t class_id = value.WrapperClassId(); const uint16_t class_id = value.WrapperClassId();
if (class_id != WrapperTypeInfo::kNodeClassId && if (class_id != WrapperTypeInfo::kNodeClassId &&
class_id != WrapperTypeInfo::kObjectClassId) class_id != WrapperTypeInfo::kObjectClassId)
...@@ -517,6 +518,11 @@ void V8EmbedderGraphBuilder::VisitTracedGlobalHandle( ...@@ -517,6 +518,11 @@ void V8EmbedderGraphBuilder::VisitTracedGlobalHandle(
VisitPersistentHandleInternal(value.As<v8::Object>().Get(isolate_), class_id); VisitPersistentHandleInternal(value.As<v8::Object>().Get(isolate_), class_id);
} }
void V8EmbedderGraphBuilder::VisitTracedGlobalHandle(
const v8::TracedGlobal<v8::Value>&) {
CHECK(false) << "Blink does not use v8::TracedGlobal.";
}
void V8EmbedderGraphBuilder::VisitPersistentHandle( void V8EmbedderGraphBuilder::VisitPersistentHandle(
v8::Persistent<v8::Value>* value, v8::Persistent<v8::Value>* value,
uint16_t class_id) { uint16_t class_id) {
......
...@@ -252,7 +252,11 @@ class DOMWrapperForwardingVisitor final ...@@ -252,7 +252,11 @@ class DOMWrapperForwardingVisitor final
VisitHandle(value, class_id); VisitHandle(value, class_id);
} }
void VisitTracedGlobalHandle(const v8::TracedGlobal<v8::Value>& value) final { void VisitTracedGlobalHandle(const v8::TracedGlobal<v8::Value>&) final {
CHECK(false) << "Blink does not use v8::TracedGlobal.";
}
void VisitTracedReference(const v8::TracedReference<v8::Value>& value) final {
VisitHandle(&value, value.WrapperClassId()); VisitHandle(&value, value.WrapperClassId());
} }
......
...@@ -229,6 +229,11 @@ class DOMDataStore { ...@@ -229,6 +229,11 @@ class DOMDataStore {
DOMWorldWrapperReference(v8::Isolate* isolate, v8::Local<v8::Object> handle) DOMWorldWrapperReference(v8::Isolate* isolate, v8::Local<v8::Object> handle)
: TraceWrapperV8Reference(isolate, handle) {} : TraceWrapperV8Reference(isolate, handle) {}
~DOMWorldWrapperReference() {
// Destruction of a reference should clear it immediately.
Clear();
}
// Move support without write barrier. // Move support without write barrier.
DOMWorldWrapperReference(DOMWorldWrapperReference&& other) DOMWorldWrapperReference(DOMWorldWrapperReference&& other)
: TraceWrapperV8Reference() { : TraceWrapperV8Reference() {
......
...@@ -161,6 +161,11 @@ class PLATFORM_EXPORT ScriptWrappable ...@@ -161,6 +161,11 @@ class PLATFORM_EXPORT ScriptWrappable
return main_world_wrapper_.NewLocal(isolate); return main_world_wrapper_.NewLocal(isolate);
} }
static_assert(
std::is_trivially_destructible<
TraceWrapperV8Reference<v8::Object>>::value,
"TraceWrapperV8Reference<v8::Object> should be trivially destructible.");
TraceWrapperV8Reference<v8::Object> main_world_wrapper_; TraceWrapperV8Reference<v8::Object> main_world_wrapper_;
DISALLOW_COPY_AND_ASSIGN(ScriptWrappable); DISALLOW_COPY_AND_ASSIGN(ScriptWrappable);
......
...@@ -11,15 +11,6 @@ ...@@ -11,15 +11,6 @@
#include "third_party/blink/renderer/platform/heap/unified_heap_marking_visitor.h" #include "third_party/blink/renderer/platform/heap/unified_heap_marking_visitor.h"
#include "v8/include/v8.h" #include "v8/include/v8.h"
namespace v8 {
template <typename T>
struct TracedGlobalTrait<v8::TracedGlobal<T>> {
static constexpr bool kRequiresExplicitDestruction = false;
};
} // namespace v8
namespace blink { namespace blink {
/** /**
...@@ -50,8 +41,8 @@ class TraceWrapperV8Reference { ...@@ -50,8 +41,8 @@ class TraceWrapperV8Reference {
bool IsEmpty() const { return handle_.IsEmpty(); } bool IsEmpty() const { return handle_.IsEmpty(); }
void Clear() { handle_.Reset(); } void Clear() { handle_.Reset(); }
ALWAYS_INLINE const v8::TracedGlobal<T>& Get() const { return handle_; } ALWAYS_INLINE const v8::TracedReference<T>& Get() const { return handle_; }
ALWAYS_INLINE v8::TracedGlobal<T>& Get() { return handle_; } ALWAYS_INLINE v8::TracedReference<T>& Get() { return handle_; }
template <typename S> template <typename S>
const TraceWrapperV8Reference<S>& Cast() const { const TraceWrapperV8Reference<S>& Cast() const {
...@@ -124,7 +115,7 @@ class TraceWrapperV8Reference { ...@@ -124,7 +115,7 @@ class TraceWrapperV8Reference {
UnifiedHeapMarkingVisitor::WriteBarrier(UnsafeCast<v8::Value>()); UnifiedHeapMarkingVisitor::WriteBarrier(UnsafeCast<v8::Value>());
} }
v8::TracedGlobal<T> handle_; v8::TracedReference<T> handle_;
}; };
} // namespace blink } // namespace blink
......
...@@ -122,7 +122,7 @@ struct WrapperTypeInfo { ...@@ -122,7 +122,7 @@ struct WrapperTypeInfo {
wrapper->SetWrapperClassId(wrapper_class_id); wrapper->SetWrapperClassId(wrapper_class_id);
} }
void ConfigureWrapper(v8::TracedGlobal<v8::Object>* wrapper) const { void ConfigureWrapper(v8::TracedReference<v8::Object>* wrapper) const {
wrapper->SetWrapperClassId(wrapper_class_id); wrapper->SetWrapperClassId(wrapper_class_id);
} }
...@@ -177,7 +177,7 @@ inline T* GetInternalField(const v8::PersistentBase<v8::Object>& persistent) { ...@@ -177,7 +177,7 @@ inline T* GetInternalField(const v8::PersistentBase<v8::Object>& persistent) {
} }
template <typename T, int offset> template <typename T, int offset>
inline T* GetInternalField(const v8::TracedGlobal<v8::Object>& global) { inline T* GetInternalField(const v8::TracedReference<v8::Object>& global) {
DCHECK_LT(offset, v8::Object::InternalFieldCount(global)); DCHECK_LT(offset, v8::Object::InternalFieldCount(global));
return reinterpret_cast<T*>( return reinterpret_cast<T*>(
v8::Object::GetAlignedPointerFromInternalField(global, offset)); v8::Object::GetAlignedPointerFromInternalField(global, offset));
...@@ -198,7 +198,7 @@ inline ScriptWrappable* ToScriptWrappable( ...@@ -198,7 +198,7 @@ inline ScriptWrappable* ToScriptWrappable(
} }
inline ScriptWrappable* ToScriptWrappable( inline ScriptWrappable* ToScriptWrappable(
const v8::TracedGlobal<v8::Object>& wrapper) { const v8::TracedReference<v8::Object>& wrapper) {
return GetInternalField<ScriptWrappable, kV8DOMWrapperObjectIndex>(wrapper); return GetInternalField<ScriptWrappable, kV8DOMWrapperObjectIndex>(wrapper);
} }
...@@ -219,7 +219,8 @@ inline void* ToUntypedWrappable(const v8::PersistentBase<v8::Object>& wrapper) { ...@@ -219,7 +219,8 @@ inline void* ToUntypedWrappable(const v8::PersistentBase<v8::Object>& wrapper) {
return GetInternalField<void, kV8DOMWrapperObjectIndex>(wrapper); return GetInternalField<void, kV8DOMWrapperObjectIndex>(wrapper);
} }
inline void* ToUntypedWrappable(const v8::TracedGlobal<v8::Object>& wrapper) { inline void* ToUntypedWrappable(
const v8::TracedReference<v8::Object>& wrapper) {
return GetInternalField<void, kV8DOMWrapperObjectIndex>(wrapper); return GetInternalField<void, kV8DOMWrapperObjectIndex>(wrapper);
} }
...@@ -233,7 +234,7 @@ inline const WrapperTypeInfo* ToWrapperTypeInfo( ...@@ -233,7 +234,7 @@ inline const WrapperTypeInfo* ToWrapperTypeInfo(
} }
inline const WrapperTypeInfo* ToWrapperTypeInfo( inline const WrapperTypeInfo* ToWrapperTypeInfo(
const v8::TracedGlobal<v8::Object>& wrapper) { const v8::TracedReference<v8::Object>& wrapper) {
return GetInternalField<WrapperTypeInfo, kV8DOMWrapperTypeIndex>(wrapper); return GetInternalField<WrapperTypeInfo, kV8DOMWrapperTypeIndex>(wrapper);
} }
......
...@@ -1288,11 +1288,15 @@ class ClearReferencesInDeadObjectsVisitor final ...@@ -1288,11 +1288,15 @@ class ClearReferencesInDeadObjectsVisitor final
value->Reset(); value->Reset();
} }
void VisitTracedGlobalHandle(const v8::TracedGlobal<v8::Value>& value) final { void VisitTracedGlobalHandle(const v8::TracedGlobal<v8::Value>&) final {
CHECK(false) << "Blink does not use v8::TracedGlobal.";
}
void VisitTracedReference(const v8::TracedReference<v8::Value>& value) final {
// TODO(mlippautz): Avoid const_cast after changing the API to allow // TODO(mlippautz): Avoid const_cast after changing the API to allow
// modificaton of the TracedGlobal handle. // modificaton of the handle.
if (InDeadObject(&const_cast<v8::TracedGlobal<v8::Value>&>(value))) if (InDeadObject(&const_cast<v8::TracedReference<v8::Value>&>(value)))
const_cast<v8::TracedGlobal<v8::Value>&>(value).Reset(); const_cast<v8::TracedReference<v8::Value>&>(value).Reset();
} }
private: private:
...@@ -1404,11 +1408,15 @@ class UnpoisonHandlesVisitor final ...@@ -1404,11 +1408,15 @@ class UnpoisonHandlesVisitor final
VisitSlot(value, sizeof(v8::Persistent<v8::Value>)); VisitSlot(value, sizeof(v8::Persistent<v8::Value>));
} }
void VisitTracedGlobalHandle(const v8::TracedGlobal<v8::Value>& value) final { void VisitTracedGlobalHandle(const v8::TracedGlobal<v8::Value>&) final {
CHECK(false) << "Blink does not use v8::TracedGlobal.";
}
void VisitTracedReference(const v8::TracedReference<v8::Value>& value) final {
// TODO(mlippautz): Avoid const_cast after changing the API to allow // TODO(mlippautz): Avoid const_cast after changing the API to allow
// modificaton of the TracedGlobal handle. // modificaton of the handle.
VisitSlot(&const_cast<v8::TracedGlobal<v8::Value>&>(value), VisitSlot(&const_cast<v8::TracedReference<v8::Value>&>(value),
sizeof(v8::TracedGlobal<v8::Value>)); sizeof(v8::TracedReference<v8::Value>));
} }
private: private:
......
...@@ -143,16 +143,19 @@ bool UnifiedHeapController::IsTracingDone() { ...@@ -143,16 +143,19 @@ bool UnifiedHeapController::IsTracingDone() {
return is_tracing_done_; return is_tracing_done_;
} }
bool UnifiedHeapController::IsRootForNonTracingGCInternal( namespace {
const v8::TracedGlobal<v8::Value>& handle) {
bool IsRootForNonTracingGCInternal(
const v8::TracedReference<v8::Value>& handle) {
const uint16_t class_id = handle.WrapperClassId(); const uint16_t class_id = handle.WrapperClassId();
// Stand-alone TracedGlobal reference or kCustomWrappableId. Keep as root as // Stand-alone reference or kCustomWrappableId. Keep as root as
// we don't know better. // we don't know better.
if (class_id != WrapperTypeInfo::kNodeClassId && if (class_id != WrapperTypeInfo::kNodeClassId &&
class_id != WrapperTypeInfo::kObjectClassId) class_id != WrapperTypeInfo::kObjectClassId)
return true; return true;
const v8::TracedGlobal<v8::Object>& traced = handle.As<v8::Object>(); const v8::TracedReference<v8::Object>& traced =
handle.template As<v8::Object>();
if (ToWrapperTypeInfo(traced)->IsActiveScriptWrappable() && if (ToWrapperTypeInfo(traced)->IsActiveScriptWrappable() &&
ToScriptWrappable(traced)->HasPendingActivity()) { ToScriptWrappable(traced)->HasPendingActivity()) {
return true; return true;
...@@ -165,8 +168,10 @@ bool UnifiedHeapController::IsRootForNonTracingGCInternal( ...@@ -165,8 +168,10 @@ bool UnifiedHeapController::IsRootForNonTracingGCInternal(
return false; return false;
} }
} // namespace
void UnifiedHeapController::ResetHandleInNonTracingGC( void UnifiedHeapController::ResetHandleInNonTracingGC(
const v8::TracedGlobal<v8::Value>& handle) { const v8::TracedReference<v8::Value>& handle) {
const uint16_t class_id = handle.WrapperClassId(); const uint16_t class_id = handle.WrapperClassId();
// Only consider handles that have not been treated as roots, see // Only consider handles that have not been treated as roots, see
// IsRootForNonTracingGCInternal. // IsRootForNonTracingGCInternal.
...@@ -174,15 +179,21 @@ void UnifiedHeapController::ResetHandleInNonTracingGC( ...@@ -174,15 +179,21 @@ void UnifiedHeapController::ResetHandleInNonTracingGC(
class_id != WrapperTypeInfo::kObjectClassId) class_id != WrapperTypeInfo::kObjectClassId)
return; return;
const v8::TracedGlobal<v8::Object>& traced = handle.As<v8::Object>(); const v8::TracedReference<v8::Object>& traced = handle.As<v8::Object>();
ToScriptWrappable(traced)->UnsetWrapperIfAny(); ToScriptWrappable(traced)->UnsetWrapperIfAny();
} }
bool UnifiedHeapController::IsRootForNonTracingGC( bool UnifiedHeapController::IsRootForNonTracingGC(
const v8::TracedGlobal<v8::Value>& handle) { const v8::TracedReference<v8::Value>& handle) {
return IsRootForNonTracingGCInternal(handle); return IsRootForNonTracingGCInternal(handle);
} }
bool UnifiedHeapController::IsRootForNonTracingGC(
const v8::TracedGlobal<v8::Value>& handle) {
CHECK(false) << "Blink does not use v8::TracedGlobal.";
return false;
}
void UnifiedHeapController::ReportBufferedAllocatedSizeIfPossible() { void UnifiedHeapController::ReportBufferedAllocatedSizeIfPossible() {
// Avoid reporting to V8 in the following conditions as that may trigger GC // Avoid reporting to V8 in the following conditions as that may trigger GC
// finalizations where not allowed. // finalizations where not allowed.
......
...@@ -45,8 +45,9 @@ class PLATFORM_EXPORT UnifiedHeapController final ...@@ -45,8 +45,9 @@ class PLATFORM_EXPORT UnifiedHeapController final
void RegisterV8References(const std::vector<std::pair<void*, void*>>&) final; void RegisterV8References(const std::vector<std::pair<void*, void*>>&) final;
bool AdvanceTracing(double) final; bool AdvanceTracing(double) final;
bool IsTracingDone() final; bool IsTracingDone() final;
bool IsRootForNonTracingGC(const v8::TracedReference<v8::Value>&) final;
bool IsRootForNonTracingGC(const v8::TracedGlobal<v8::Value>&) final; bool IsRootForNonTracingGC(const v8::TracedGlobal<v8::Value>&) final;
void ResetHandleInNonTracingGC(const v8::TracedGlobal<v8::Value>&) final; void ResetHandleInNonTracingGC(const v8::TracedReference<v8::Value>&) final;
ThreadState* thread_state() const { return thread_state_; } ThreadState* thread_state() const { return thread_state_; }
...@@ -59,9 +60,6 @@ class PLATFORM_EXPORT UnifiedHeapController final ...@@ -59,9 +60,6 @@ class PLATFORM_EXPORT UnifiedHeapController final
void DecreaseAllocatedSpace(size_t) final {} void DecreaseAllocatedSpace(size_t) final {}
private: private:
static bool IsRootForNonTracingGCInternal(
const v8::TracedGlobal<v8::Value>& handle);
void ReportBufferedAllocatedSizeIfPossible(); void ReportBufferedAllocatedSizeIfPossible();
ThreadState* const thread_state_; ThreadState* const thread_state_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment