bc12982d51
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}
51 lines
1.3 KiB
C++
51 lines
1.3 KiB
C++
// 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_
|