Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 struct FinalizerTraitImpl<T, false> { | 145 struct FinalizerTraitImpl<T, false> { |
| 146 static void finalize(void* obj) { }; | 146 static void finalize(void* obj) { }; |
| 147 }; | 147 }; |
| 148 | 148 |
| 149 // Default trait uses the automatic detection. | 149 // Default trait uses the automatic detection. |
| 150 template<typename T> struct FinalizerTrait { | 150 template<typename T> struct FinalizerTrait { |
| 151 static const bool nonTrivialFinalizer = HasFinalizer<T>::value; | 151 static const bool nonTrivialFinalizer = HasFinalizer<T>::value; |
| 152 static void finalize(void* obj) { FinalizerTraitImpl<T, nonTrivialFinalizer> ::finalize(obj); } | 152 static void finalize(void* obj) { FinalizerTraitImpl<T, nonTrivialFinalizer> ::finalize(obj); } |
| 153 }; | 153 }; |
| 154 | 154 |
| 155 #define DECLARE_GC_INFO \ | 155 #define DECLARE_GC_INFO |
| 156 public: \ | 156 #define DEFINE_GC_INFO(Type) |
| 157 static const GCInfo s_gcInfo; \ | |
| 158 template<typename Any> friend struct FinalizerTrait; \ | |
| 159 private: \ | |
| 160 | 157 |
| 161 #define DEFINE_GC_INFO(Type) \ | 158 template<typename T> struct GCInfoTrait; |
| 162 const GCInfo Type::s_gcInfo = { \ | |
| 163 #Type, \ | |
| 164 TraceTrait<Type>::trace, \ | |
| 165 FinalizerTrait<Type>::finalize, \ | |
| 166 FinalizerTrait<Type>::nonTrivialFinalizer, \ | |
| 167 CLASSOF_FUNC(Type) \ | |
| 168 }; \ | |
| 169 | |
| 170 template<typename T> | |
| 171 struct GCInfoTrait { | |
| 172 static const GCInfo* get() | |
| 173 { | |
| 174 return &T::s_gcInfo; | |
| 175 } | |
| 176 }; | |
| 177 | 159 |
| 178 template<typename T> | 160 template<typename T> |
| 179 const char* getTypeMarker() | 161 const char* getTypeMarker() |
| 180 { | 162 { |
| 181 return GCInfoTrait<T>::get()->m_typeMarker; | 163 return GCInfoTrait<T>::get()->m_typeMarker; |
| 182 } | 164 } |
| 183 | 165 |
| 184 // Most classes that have instances on the heap have an trace method, which is | 166 // Most classes that have instances on the heap have an trace method, which is |
| 185 // used to trace the pointers to other heap objects inside an object. | 167 // used to trace the pointers to other heap objects inside an object. |
| 186 template<typename T> | 168 template<typename T> |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 525 } | 507 } |
| 526 | 508 |
| 527 class HeapVisitable { | 509 class HeapVisitable { |
| 528 public: | 510 public: |
| 529 virtual void trace(Visitor*) = 0; | 511 virtual void trace(Visitor*) = 0; |
| 530 virtual ~HeapVisitable() | 512 virtual ~HeapVisitable() |
| 531 { | 513 { |
| 532 } | 514 } |
| 533 }; | 515 }; |
| 534 | 516 |
| 517 template<typename T> | |
| 518 struct GCInfoAtBase { | |
| 519 static const GCInfo* get() | |
| 520 { | |
| 521 static char foo = 'a'; // FIXME | |
|
haraken
2014/02/19 02:51:40
foo => type (or className)
Add more description.
kouhei (in TOK)
2014/02/19 03:08:20
@Slava
I want your suggestions here. I'm not sure
zerny-chromium
2014/02/19 09:44:48
We only need the type marker on debug builds so we
kouhei (in TOK)
2014/02/19 11:57:27
Thanks for your comment.
Just to clarify, the abo
Vyacheslav Egorov (Chromium)
2014/02/19 15:03:31
CLASSOF_FUNC could delegate to a virtual classOf m
kouhei (in TOK)
2014/02/20 01:07:41
Thanks, Slava!
I'll split work and do the followin
| |
| 522 static const GCInfo gcInfo = { | |
| 523 &foo, | |
| 524 TraceTrait<T>::trace, | |
| 525 FinalizerTrait<T>::finalize, | |
| 526 FinalizerTrait<T>::nonTrivialFinalizer, | |
| 527 CLASSOF_FUNC(T) | |
| 528 }; | |
| 529 return &gcInfo; | |
| 530 } | |
| 531 }; | |
| 532 | |
| 533 template<typename T> | |
| 534 struct GCInfoTrait { | |
| 535 static const GCInfo* get() | |
| 536 { | |
| 537 return GCInfoAtBase<typename T::HeapAllocatedBase>::get(); | |
| 538 } | |
| 539 }; | |
| 540 | |
| 535 } | 541 } |
| 542 | |
| 536 #endif | 543 #endif |
| OLD | NEW |