V8
latest master commit
V8 is Google's open source JavaScript engine
prefinalizer.h
Go to the documentation of this file.
1
// Copyright 2020 the V8 project authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file.
4
5
#ifndef INCLUDE_CPPGC_PREFINALIZER_H_
6
#define INCLUDE_CPPGC_PREFINALIZER_H_
7
8
#include "
cppgc/internal/accessors.h
"
9
#include "
cppgc/internal/compiler-specific.h
"
10
#include "
cppgc/internal/prefinalizer-handler.h
"
11
#include "
cppgc/liveness-broker.h
"
12
13
namespace
cppgc
{
14
15
namespace
internal {
16
17
template
<
typename
T>
18
class
PrefinalizerRegistration
final {
19
public
:
20
explicit
PrefinalizerRegistration
(T*
self
) {
21
static_assert(
sizeof
(&T::InvokePreFinalizer) > 0,
22
"USING_PRE_FINALIZER(T) must be defined."
);
23
24
cppgc::internal::PreFinalizerRegistrationDispatcher::RegisterPrefinalizer
(
25
internal::GetHeapFromPayload
(
self
), {
self
, T::InvokePreFinalizer});
26
}
27
28
void
*
operator
new
(size_t,
void
* location) =
delete
;
29
void
*
operator
new
(size_t) =
delete
;
30
};
31
32
}
// namespace internal
33
34
#define CPPGC_USING_PRE_FINALIZER(Class, PreFinalizer) \
35
public: \
36
static bool InvokePreFinalizer(const LivenessBroker& liveness_broker, \
37
void* object) { \
38
static_assert(internal::IsGarbageCollectedTypeV<Class>, \
39
"Only garbage collected objects can have prefinalizers"); \
40
Class* self = static_cast<Class*>(object); \
41
if (liveness_broker.IsHeapObjectAlive(self)) return false; \
42
self->Class::PreFinalizer(); \
43
return true; \
44
} \
45
\
46
private: \
47
CPPGC_NO_UNIQUE_ADDRESS internal::PrefinalizerRegistration<Class> \
48
prefinalizer_dummy_{this}; \
49
static_assert(true, "Force semicolon.")
50
51
}
// namespace cppgc
52
53
#endif // INCLUDE_CPPGC_PREFINALIZER_H_
accessors.h
cppgc::internal::GetHeapFromPayload
cppgc::Heap * GetHeapFromPayload(const void *payload)
Definition:
accessors.h:16
cppgc::internal::PrefinalizerRegistration
Definition:
prefinalizer.h:18
compiler-specific.h
cppgc
Definition:
allocation.h:18
prefinalizer-handler.h
cppgc::internal::PrefinalizerRegistration::PrefinalizerRegistration
PrefinalizerRegistration(T *self)
Definition:
prefinalizer.h:20
liveness-broker.h
cppgc::internal::PreFinalizerRegistrationDispatcher::RegisterPrefinalizer
static void RegisterPrefinalizer(cppgc::Heap *heap, PreFinalizer prefinalzier)
v8
include
cppgc
prefinalizer.h
Generated by
1.8.17