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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 struct FinalizerTraitImpl<T, false> { | 146 struct FinalizerTraitImpl<T, false> { |
147 static void finalize(void* obj) { }; | 147 static void finalize(void* obj) { }; |
148 }; | 148 }; |
149 | 149 |
150 // Default trait uses the automatic detection. | 150 // Default trait uses the automatic detection. |
151 template<typename T> struct FinalizerTrait { | 151 template<typename T> struct FinalizerTrait { |
152 static const bool nonTrivialFinalizer = HasFinalizer<T>::value; | 152 static const bool nonTrivialFinalizer = HasFinalizer<T>::value; |
153 static void finalize(void* obj) { FinalizerTraitImpl<T, nonTrivialFinalizer>
::finalize(obj); } | 153 static void finalize(void* obj) { FinalizerTraitImpl<T, nonTrivialFinalizer>
::finalize(obj); } |
154 }; | 154 }; |
155 | 155 |
156 #define DECLARE_GC_INFO \ | 156 #define DECLARE_GC_INFO |
157 public: \ | 157 #define DEFINE_GC_INFO(Type) |
158 static const GCInfo s_gcInfo; \ | |
159 template<typename Any> friend struct FinalizerTrait; \ | |
160 private: \ | |
161 | 158 |
162 #define DEFINE_GC_INFO(Type) \ | 159 template<typename T> struct GCInfoTrait; |
163 const GCInfo Type::s_gcInfo = { \ | |
164 #Type, \ | |
165 TraceTrait<Type>::trace, \ | |
166 FinalizerTrait<Type>::finalize, \ | |
167 FinalizerTrait<Type>::nonTrivialFinalizer, \ | |
168 CLASSOF_FUNC(Type) \ | |
169 }; \ | |
170 | |
171 template<typename T> | |
172 struct GCInfoTrait { | |
173 static const GCInfo* get() | |
174 { | |
175 return &T::s_gcInfo; | |
176 } | |
177 }; | |
178 | 160 |
179 template<typename T> | 161 template<typename T> |
180 const char* getTypeMarker() | 162 const char* getTypeMarker() |
181 { | 163 { |
182 return GCInfoTrait<T>::get()->m_typeMarker; | 164 return GCInfoTrait<T>::get()->m_typeMarker; |
183 } | 165 } |
184 | 166 |
185 // Most classes that have instances on the heap have an trace method, which is | 167 // Most classes that have instances on the heap have an trace method, which is |
186 // used to trace the pointers to other heap objects inside an object. | 168 // used to trace the pointers to other heap objects inside an object. |
187 template<typename T> | 169 template<typename T> |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 } | 529 } |
548 | 530 |
549 class HeapVisitable { | 531 class HeapVisitable { |
550 public: | 532 public: |
551 virtual void trace(Visitor*) = 0; | 533 virtual void trace(Visitor*) = 0; |
552 virtual ~HeapVisitable() | 534 virtual ~HeapVisitable() |
553 { | 535 { |
554 } | 536 } |
555 }; | 537 }; |
556 | 538 |
| 539 template<typename T> |
| 540 struct GCInfoAtBase { |
| 541 static const GCInfo* get() |
| 542 { |
| 543 static char pseudoTypeMarker = 'a'; // FIXME: This is to be removed |
| 544 static const GCInfo gcInfo = { |
| 545 &pseudoTypeMarker, |
| 546 TraceTrait<T>::trace, |
| 547 FinalizerTrait<T>::finalize, |
| 548 FinalizerTrait<T>::nonTrivialFinalizer, |
| 549 CLASSOF_FUNC(T) |
| 550 }; |
| 551 return &gcInfo; |
| 552 } |
| 553 }; |
| 554 |
| 555 template<typename T> |
| 556 struct GCInfoTrait { |
| 557 static const GCInfo* get() |
| 558 { |
| 559 return GCInfoAtBase<typename T::GarbageCollectedBase>::get(); |
| 560 } |
| 561 }; |
| 562 |
557 } | 563 } |
| 564 |
558 #endif | 565 #endif |
OLD | NEW |