| 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 // By default classes that inherit from GarbageCollectedFinalized need | 127 // By default classes that inherit from GarbageCollectedFinalized need |
| 128 // finalization and finalization means calling the 'finalize' method | 128 // finalization and finalization means calling the 'finalize' method |
| 129 // of the object. The FinalizerTrait can be specialized if the default | 129 // of the object. The FinalizerTrait can be specialized if the default |
| 130 // behavior is not desired. | 130 // behavior is not desired. |
| 131 template<typename T> | 131 template<typename T> |
| 132 struct FinalizerTrait { | 132 struct FinalizerTrait { |
| 133 static const bool nonTrivialFinalizer = IsGarbageCollectedFinalized<T>::valu
e; | 133 static const bool nonTrivialFinalizer = IsGarbageCollectedFinalized<T>::valu
e; |
| 134 static void finalize(void* obj) { FinalizerTraitImpl<T, nonTrivialFinalizer>
::finalize(obj); } | 134 static void finalize(void* obj) { FinalizerTraitImpl<T, nonTrivialFinalizer>
::finalize(obj); } |
| 135 }; | 135 }; |
| 136 | 136 |
| 137 // Macros to declare and define GCInfo structures for objects | |
| 138 // allocated in the Blink garbage-collected heap. | |
| 139 #define DECLARE_GC_INFO \ | |
| 140 public: \ | |
| 141 static const GCInfo s_gcInfo; \ | |
| 142 template<typename Any> friend struct FinalizerTrait; \ | |
| 143 private: \ | |
| 144 | |
| 145 #define DEFINE_GC_INFO(Type) \ | |
| 146 const GCInfo Type::s_gcInfo = { \ | |
| 147 #Type, \ | |
| 148 TraceTrait<Type>::trace, \ | |
| 149 FinalizerTrait<Type>::finalize, \ | |
| 150 FinalizerTrait<Type>::nonTrivialFinalizer, \ | |
| 151 }; \ | |
| 152 | |
| 153 // Trait to get the GCInfo structure for types that have their | 137 // Trait to get the GCInfo structure for types that have their |
| 154 // instances allocated in the Blink garbage-collected heap. | 138 // instances allocated in the Blink garbage-collected heap. |
| 155 template<typename T> | 139 template<typename T> struct GCInfoTrait; |
| 156 struct GCInfoTrait { | |
| 157 static const GCInfo* get() | |
| 158 { | |
| 159 return &T::s_gcInfo; | |
| 160 } | |
| 161 }; | |
| 162 | 140 |
| 163 template<typename T> | 141 template<typename T> |
| 164 const char* getTypeMarker() | 142 const char* getTypeMarker() |
| 165 { | 143 { |
| 166 return GCInfoTrait<T>::get()->m_typeMarker; | 144 return GCInfoTrait<T>::get()->m_typeMarker; |
| 167 } | 145 } |
| 168 | 146 |
| 169 // The TraceTrait is used to specify how to mark an object pointer and | 147 // The TraceTrait is used to specify how to mark an object pointer and |
| 170 // how to trace all of the pointers in the object. | 148 // how to trace all of the pointers in the object. |
| 171 // | 149 // |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 | 516 |
| 539 template<typename T> bool ObjectAliveTrait<T>::isAlive(Visitor* visitor, T obj) | 517 template<typename T> bool ObjectAliveTrait<T>::isAlive(Visitor* visitor, T obj) |
| 540 { | 518 { |
| 541 return visitor->isMarked(obj); | 519 return visitor->isMarked(obj); |
| 542 } | 520 } |
| 543 template<typename T> bool ObjectAliveTrait<Member<T> >::isAlive(Visitor* visitor
, const Member<T>& obj) | 521 template<typename T> bool ObjectAliveTrait<Member<T> >::isAlive(Visitor* visitor
, const Member<T>& obj) |
| 544 { | 522 { |
| 545 return visitor->isMarked(obj.get()); | 523 return visitor->isMarked(obj.get()); |
| 546 } | 524 } |
| 547 | 525 |
| 526 template<typename T> |
| 527 struct GCInfoAtBase { |
| 528 static const GCInfo* get() |
| 529 { |
| 530 static char pseudoTypeMarker = 'a'; |
| 531 static const GCInfo gcInfo = { |
| 532 &pseudoTypeMarker, |
| 533 TraceTrait<T>::trace, |
| 534 FinalizerTrait<T>::finalize, |
| 535 FinalizerTrait<T>::nonTrivialFinalizer, |
| 536 }; |
| 537 return &gcInfo; |
| 538 } |
| 539 }; |
| 540 |
| 541 template<typename T> |
| 542 struct GCInfoTrait { |
| 543 static const GCInfo* get() |
| 544 { |
| 545 return GCInfoAtBase<typename T::GarbageCollectedBase>::get(); |
| 546 } |
| 547 }; |
| 548 |
| 548 } | 549 } |
| 549 | 550 |
| 550 #endif | 551 #endif |
| OLD | NEW |