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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 | 137 // Macros to declare and define GCInfo structures for objects |
138 // allocated in the Blink garbage-collected heap. | 138 // allocated in the Blink garbage-collected heap. |
139 #define DECLARE_GC_INFO \ | 139 #define DECLARE_GC_INFO |
140 public: \ | 140 #define DEFINE_GC_INFO(Type) |
141 static const GCInfo s_gcInfo; \ | |
142 template<typename Any> friend struct FinalizerTrait; \ | |
Mads Ager (chromium)
2014/02/17 07:22:07
Here we are losing a friend declaration. Maybe tha
kouhei (in TOK)
2014/02/17 08:35:53
This friend stmt is for calling |finalize()| metho
wibling-chromium
2014/02/17 08:44:15
Can't we add the friend declaration to GarbageColl
kouhei (in TOK)
2014/02/17 08:48:19
Yes. I think we can add the friend decl to Garbage
| |
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 | 141 |
153 // Trait to get the GCInfo structure for types that have their | 142 // Trait to get the GCInfo structure for types that have their |
154 // instances allocated in the Blink garbage-collected heap. | 143 // instances allocated in the Blink garbage-collected heap. |
155 template<typename T> | 144 template<typename T> struct GCInfoTrait; |
156 struct GCInfoTrait { | |
157 static const GCInfo* get() | |
158 { | |
159 return &T::s_gcInfo; | |
160 } | |
161 }; | |
162 | 145 |
163 template<typename T> | 146 template<typename T> |
164 const char* getTypeMarker() | 147 const char* getTypeMarker() |
165 { | 148 { |
166 return GCInfoTrait<T>::get()->m_typeMarker; | 149 return GCInfoTrait<T>::get()->m_typeMarker; |
167 } | 150 } |
168 | 151 |
169 // The TraceTrait is used to specify how to mark an object pointer and | 152 // The TraceTrait is used to specify how to mark an object pointer and |
170 // how to trace all of the pointers in the object. | 153 // how to trace all of the pointers in the object. |
171 // | 154 // |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
540 | 523 |
541 template<typename T> bool ObjectAliveTrait<T>::isAlive(Visitor* visitor, T obj) | 524 template<typename T> bool ObjectAliveTrait<T>::isAlive(Visitor* visitor, T obj) |
542 { | 525 { |
543 return visitor->isMarked(obj); | 526 return visitor->isMarked(obj); |
544 } | 527 } |
545 template<typename T> bool ObjectAliveTrait<Member<T> >::isAlive(Visitor* visitor , const Member<T>& obj) | 528 template<typename T> bool ObjectAliveTrait<Member<T> >::isAlive(Visitor* visitor , const Member<T>& obj) |
546 { | 529 { |
547 return visitor->isMarked(obj.get()); | 530 return visitor->isMarked(obj.get()); |
548 } | 531 } |
549 | 532 |
533 template<typename T> | |
534 struct GCInfoKeep | |
535 { | |
536 static const GCInfo* get() | |
537 { | |
538 static char foo = 'a'; // FIXME: use extractNameFromFunctionName() | |
539 static const GCInfo gcInfo = { | |
Mads Ager (chromium)
2014/02/17 07:22:07
The other difference with this is that these struc
kouhei (in TOK)
2014/02/17 08:35:53
There is no difference in generated code.
I tested
| |
540 &foo, | |
541 TraceTrait<T>::trace, | |
542 FinalizerTrait<T>::finalize, | |
543 FinalizerTrait<T>::nonTrivialFinalizer, | |
544 }; | |
545 return &gcInfo; | |
546 } | |
547 }; | |
548 | |
549 template<typename T> | |
550 struct GCInfoTrait | |
551 { | |
552 static const GCInfo* get() | |
553 { | |
554 return GCInfoKeep<typename T::GarbageCollectedBase>::get(); | |
555 } | |
556 }; | |
557 | |
550 } | 558 } |
551 | 559 |
552 #endif | 560 #endif |
OLD | NEW |