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 #include "include/cppgc/internal/gc-info.h"
6 
7 #include "include/cppgc/internal/name-trait.h"
8 #include "include/v8config.h"
9 #include "src/heap/cppgc/gc-info-table.h"
10 
11 namespace cppgc {
12 namespace internal {
13 
14 namespace {
15 
GetHiddenName(const void *)16 HeapObjectName GetHiddenName(const void*) {
17   return {NameProvider::kHiddenName, true};
18 }
19 
20 }  // namespace
21 
22 // static
EnsureGCInfoIndexPolymorphic(std::atomic<GCInfoIndex> & registered_index,TraceCallback trace_callback,FinalizationCallback finalization_callback,NameCallback name_callback)23 GCInfoIndex EnsureGCInfoIndexTrait::EnsureGCInfoIndexPolymorphic(
24     std::atomic<GCInfoIndex>& registered_index, TraceCallback trace_callback,
25     FinalizationCallback finalization_callback, NameCallback name_callback) {
26   return GlobalGCInfoTable::GetMutable().RegisterNewGCInfo(
27       registered_index,
28       {finalization_callback, trace_callback, name_callback, true});
29 }
30 
31 // static
EnsureGCInfoIndexPolymorphic(std::atomic<GCInfoIndex> & registered_index,TraceCallback trace_callback,FinalizationCallback finalization_callback)32 GCInfoIndex EnsureGCInfoIndexTrait::EnsureGCInfoIndexPolymorphic(
33     std::atomic<GCInfoIndex>& registered_index, TraceCallback trace_callback,
34     FinalizationCallback finalization_callback) {
35   return GlobalGCInfoTable::GetMutable().RegisterNewGCInfo(
36       registered_index,
37       {finalization_callback, trace_callback, GetHiddenName, true});
38 }
39 
40 // static
EnsureGCInfoIndexPolymorphic(std::atomic<GCInfoIndex> & registered_index,TraceCallback trace_callback,NameCallback name_callback)41 GCInfoIndex EnsureGCInfoIndexTrait::EnsureGCInfoIndexPolymorphic(
42     std::atomic<GCInfoIndex>& registered_index, TraceCallback trace_callback,
43     NameCallback name_callback) {
44   return GlobalGCInfoTable::GetMutable().RegisterNewGCInfo(
45       registered_index, {nullptr, trace_callback, name_callback, true});
46 }
47 
48 // static
EnsureGCInfoIndexPolymorphic(std::atomic<GCInfoIndex> & registered_index,TraceCallback trace_callback)49 GCInfoIndex EnsureGCInfoIndexTrait::EnsureGCInfoIndexPolymorphic(
50     std::atomic<GCInfoIndex>& registered_index, TraceCallback trace_callback) {
51   return GlobalGCInfoTable::GetMutable().RegisterNewGCInfo(
52       registered_index, {nullptr, trace_callback, GetHiddenName, true});
53 }
54 
55 // static
EnsureGCInfoIndexNonPolymorphic(std::atomic<GCInfoIndex> & registered_index,TraceCallback trace_callback,FinalizationCallback finalization_callback,NameCallback name_callback)56 GCInfoIndex EnsureGCInfoIndexTrait::EnsureGCInfoIndexNonPolymorphic(
57     std::atomic<GCInfoIndex>& registered_index, TraceCallback trace_callback,
58     FinalizationCallback finalization_callback, NameCallback name_callback) {
59   return GlobalGCInfoTable::GetMutable().RegisterNewGCInfo(
60       registered_index,
61       {finalization_callback, trace_callback, name_callback, false});
62 }
63 
64 // static
EnsureGCInfoIndexNonPolymorphic(std::atomic<GCInfoIndex> & registered_index,TraceCallback trace_callback,FinalizationCallback finalization_callback)65 GCInfoIndex EnsureGCInfoIndexTrait::EnsureGCInfoIndexNonPolymorphic(
66     std::atomic<GCInfoIndex>& registered_index, TraceCallback trace_callback,
67     FinalizationCallback finalization_callback) {
68   return GlobalGCInfoTable::GetMutable().RegisterNewGCInfo(
69       registered_index,
70       {finalization_callback, trace_callback, GetHiddenName, false});
71 }
72 
73 // static
EnsureGCInfoIndexNonPolymorphic(std::atomic<GCInfoIndex> & registered_index,TraceCallback trace_callback,NameCallback name_callback)74 GCInfoIndex EnsureGCInfoIndexTrait::EnsureGCInfoIndexNonPolymorphic(
75     std::atomic<GCInfoIndex>& registered_index, TraceCallback trace_callback,
76     NameCallback name_callback) {
77   return GlobalGCInfoTable::GetMutable().RegisterNewGCInfo(
78       registered_index, {nullptr, trace_callback, name_callback, false});
79 }
80 
81 // static
EnsureGCInfoIndexNonPolymorphic(std::atomic<GCInfoIndex> & registered_index,TraceCallback trace_callback)82 GCInfoIndex EnsureGCInfoIndexTrait::EnsureGCInfoIndexNonPolymorphic(
83     std::atomic<GCInfoIndex>& registered_index, TraceCallback trace_callback) {
84   return GlobalGCInfoTable::GetMutable().RegisterNewGCInfo(
85       registered_index, {nullptr, trace_callback, GetHiddenName, false});
86 }
87 
88 }  // namespace internal
89 }  // namespace cppgc
90