cppgc: LivenessBroker
Introduce LivenessBroker which is a temporary broker object to expose liveness during specific garbage collection phases. This broker can be used to handle: - PreFinalizer - Custom weak callbacks - Internal weak callbacks used for WeakMember Change-Id: I3870c2b89b2538f04feabf2eb7a4676ce2fe7d61 Bug: chromium:1056170 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2144059 Reviewed-by: Omer Katz <omerkatz@chromium.org> Reviewed-by: Ulan Degenbaev <ulan@chromium.org> Commit-Queue: Michael Lippautz <mlippautz@chromium.org> Cr-Commit-Position: refs/heads/master@{#67107}
This commit is contained in:
parent
3a4b9940b3
commit
bc12982d51
2
BUILD.gn
2
BUILD.gn
@ -3954,6 +3954,7 @@ v8_source_set("cppgc_base") {
|
||||
"include/cppgc/internal/finalizer-traits.h",
|
||||
"include/cppgc/internal/gc-info.h",
|
||||
"include/cppgc/internal/pointer-policies.h",
|
||||
"include/cppgc/liveness-broker.h",
|
||||
"include/cppgc/member.h",
|
||||
"include/cppgc/platform.h",
|
||||
"include/cppgc/source-location.h",
|
||||
@ -3973,6 +3974,7 @@ v8_source_set("cppgc_base") {
|
||||
"src/heap/cppgc/heap-page.h",
|
||||
"src/heap/cppgc/heap.cc",
|
||||
"src/heap/cppgc/heap.h",
|
||||
"src/heap/cppgc/liveness-broker.cc",
|
||||
"src/heap/cppgc/platform.cc",
|
||||
"src/heap/cppgc/pointer-policies.cc",
|
||||
"src/heap/cppgc/sanitizers.h",
|
||||
|
50
include/cppgc/liveness-broker.h
Normal file
50
include/cppgc/liveness-broker.h
Normal file
@ -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_LIVENESS_BROKER_H_
|
||||
#define INCLUDE_CPPGC_LIVENESS_BROKER_H_
|
||||
|
||||
#include "include/cppgc/heap.h"
|
||||
#include "include/cppgc/member.h"
|
||||
#include "include/cppgc/trace-trait.h"
|
||||
#include "include/v8config.h"
|
||||
|
||||
namespace cppgc {
|
||||
|
||||
namespace internal {
|
||||
class LivenessBrokerFactory;
|
||||
} // namespace internal
|
||||
|
||||
class V8_EXPORT LivenessBroker final {
|
||||
public:
|
||||
template <typename T>
|
||||
bool IsHeapObjectAlive(const T* object) const {
|
||||
return object &&
|
||||
IsHeapObjectAliveImpl(
|
||||
TraceTrait<T>::GetTraceDescriptor(object).base_object_payload);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool IsHeapObjectAlive(const WeakMember<T>& weak_member) const {
|
||||
return (weak_member != kSentinelPointer) &&
|
||||
IsHeapObjectAlive<T>(weak_member.Get());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool IsHeapObjectAlive(const UntracedMember<T>& untraced_member) const {
|
||||
return (untraced_member != kSentinelPointer) &&
|
||||
IsHeapObjectAlive<T>(untraced_member.Get());
|
||||
}
|
||||
|
||||
private:
|
||||
LivenessBroker() = default;
|
||||
|
||||
bool IsHeapObjectAliveImpl(const void*) const;
|
||||
|
||||
friend class internal::LivenessBrokerFactory;
|
||||
};
|
||||
|
||||
} // namespace cppgc
|
||||
|
||||
#endif // INCLUDE_CPPGC_LIVENESS_BROKER_H_
|
@ -27,6 +27,11 @@ constexpr bool NeedsConservativeStackScan(Heap::GCConfig config) {
|
||||
|
||||
} // namespace
|
||||
|
||||
// static
|
||||
cppgc::LivenessBroker LivenessBrokerFactory::Create() {
|
||||
return cppgc::LivenessBroker();
|
||||
}
|
||||
|
||||
// TODO(chromium:1056170): Replace with fast stack scanning once
|
||||
// object are allocated actual arenas/spaces.
|
||||
class StackMarker final : public StackVisitor {
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
#include "include/cppgc/heap.h"
|
||||
#include "include/cppgc/internal/gc-info.h"
|
||||
#include "include/cppgc/liveness-broker.h"
|
||||
#include "src/heap/cppgc/heap-object-header.h"
|
||||
|
||||
namespace cppgc {
|
||||
@ -18,6 +19,11 @@ namespace internal {
|
||||
class NormalPage;
|
||||
class Stack;
|
||||
|
||||
class V8_EXPORT_PRIVATE LivenessBrokerFactory {
|
||||
public:
|
||||
static LivenessBroker Create();
|
||||
};
|
||||
|
||||
class V8_EXPORT_PRIVATE Heap final : public cppgc::Heap {
|
||||
public:
|
||||
class V8_EXPORT_PRIVATE NoGCScope final {
|
||||
|
15
src/heap/cppgc/liveness-broker.cc
Normal file
15
src/heap/cppgc/liveness-broker.cc
Normal file
@ -0,0 +1,15 @@
|
||||
// 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.
|
||||
|
||||
#include "include/cppgc/liveness-broker.h"
|
||||
|
||||
#include "src/heap/cppgc/heap-object-header-inl.h"
|
||||
|
||||
namespace cppgc {
|
||||
|
||||
bool LivenessBroker::IsHeapObjectAliveImpl(const void* payload) const {
|
||||
return internal::HeapObjectHeader::FromPayload(payload).IsMarked();
|
||||
}
|
||||
|
||||
} // namespace cppgc
|
Loading…
Reference in New Issue
Block a user