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_INTERNAL_GC_INFO_H_ 6 #define INCLUDE_CPPGC_INTERNAL_GC_INFO_H_ 7 8 #include <stdint.h> 9 10 #include "cppgc/internal/finalizer-trait.h" 11 #include "cppgc/internal/name-trait.h" 12 #include "cppgc/trace-trait.h" 13 #include "v8config.h" // NOLINT(build/include_directory) 14 15 namespace cppgc { 16 namespace internal { 17 18 using GCInfoIndex = uint16_t; 19 20 class V8_EXPORT RegisteredGCInfoIndex final { 21 public: 22 RegisteredGCInfoIndex(FinalizationCallback finalization_callback, 23 TraceCallback trace_callback, 24 NameCallback name_callback, bool has_v_table); GetIndex()25 GCInfoIndex GetIndex() const { return index_; } 26 27 private: 28 const GCInfoIndex index_; 29 }; 30 31 // Trait determines how the garbage collector treats objects wrt. to traversing, 32 // finalization, and naming. 33 template <typename T> 34 struct GCInfoTrait { IndexGCInfoTrait35 static GCInfoIndex Index() { 36 static_assert(sizeof(T), "T must be fully defined"); 37 static const RegisteredGCInfoIndex registered_index( 38 FinalizerTrait<T>::kCallback, TraceTrait<T>::Trace, 39 NameTrait<T>::GetName, std::is_polymorphic<T>::value); 40 return registered_index.GetIndex(); 41 } 42 }; 43 44 } // namespace internal 45 } // namespace cppgc 46 47 #endif // INCLUDE_CPPGC_INTERNAL_GC_INFO_H_ 48