OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 | 97 |
98 | 98 |
99 template <typename T> | 99 template <typename T> |
100 struct LeakyInstanceTrait { | 100 struct LeakyInstanceTrait { |
101 static void Destroy(T* /* instance */) {} | 101 static void Destroy(T* /* instance */) {} |
102 }; | 102 }; |
103 | 103 |
104 | 104 |
105 // Traits that define how an instance is allocated and accessed. | 105 // Traits that define how an instance is allocated and accessed. |
106 | 106 |
107 #if V8_HOST_ARCH_MIPS | |
danno
2012/03/16 12:40:08
I'd prefer avoiding the platform-specific define.
| |
108 #define LAZY_ALIGN(x) __attribute__((aligned(__alignof__(x)))) | |
109 #else // V8_HOST_ARCH_MIPS | |
110 #define LAZY_ALIGN(x) | |
111 #endif | |
112 | |
107 template <typename T> | 113 template <typename T> |
108 struct StaticallyAllocatedInstanceTrait { | 114 struct StaticallyAllocatedInstanceTrait { |
109 typedef char StorageType[sizeof(T)]; | 115 typedef char StorageType[sizeof(T)] LAZY_ALIGN(T); |
110 | 116 |
111 static T* MutableInstance(StorageType* storage) { | 117 static T* MutableInstance(StorageType* storage) { |
112 return reinterpret_cast<T*>(storage); | 118 return reinterpret_cast<T*>(storage); |
113 } | 119 } |
114 | 120 |
115 template <typename ConstructTrait> | 121 template <typename ConstructTrait> |
116 static void InitStorageUsingTrait(StorageType* storage) { | 122 static void InitStorageUsingTrait(StorageType* storage) { |
117 ConstructTrait::Construct(MutableInstance(storage)); | 123 ConstructTrait::Construct(MutableInstance(storage)); |
118 } | 124 } |
119 }; | 125 }; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 Init(); | 178 Init(); |
173 return AllocationTrait::MutableInstance(&storage_); | 179 return AllocationTrait::MutableInstance(&storage_); |
174 } | 180 } |
175 | 181 |
176 const T& Get() const { | 182 const T& Get() const { |
177 Init(); | 183 Init(); |
178 return *AllocationTrait::MutableInstance(&storage_); | 184 return *AllocationTrait::MutableInstance(&storage_); |
179 } | 185 } |
180 | 186 |
181 mutable OnceType once_; | 187 mutable OnceType once_; |
182 // Note that the previous field, OnceType, is an AtomicWord which guarantees | 188 // Note that the previous field, OnceType, is an AtomicWord which guarantees |
Philippe
2012/03/16 12:24:30
We noticed this issue and thought that we could te
danno
2012/03/16 12:40:08
Done.
| |
183 // the correct alignment of the storage field below. | 189 // the correct alignment of the storage field below. |
184 mutable StorageType storage_; | 190 mutable StorageType storage_; |
185 }; | 191 }; |
186 | 192 |
187 | 193 |
188 template <typename T, | 194 template <typename T, |
189 typename CreateTrait = DefaultConstructTrait<T>, | 195 typename CreateTrait = DefaultConstructTrait<T>, |
190 typename DestroyTrait = LeakyInstanceTrait<T> > | 196 typename DestroyTrait = LeakyInstanceTrait<T> > |
191 struct LazyStaticInstance { | 197 struct LazyStaticInstance { |
192 typedef LazyInstanceImpl<T, StaticallyAllocatedInstanceTrait<T>, CreateTrait, | 198 typedef LazyInstanceImpl<T, StaticallyAllocatedInstanceTrait<T>, CreateTrait, |
(...skipping 14 matching lines...) Expand all Loading... | |
207 typename CreateTrait = DefaultConstructTrait<T>, | 213 typename CreateTrait = DefaultConstructTrait<T>, |
208 typename DestroyTrait = LeakyInstanceTrait<T> > | 214 typename DestroyTrait = LeakyInstanceTrait<T> > |
209 struct LazyDynamicInstance { | 215 struct LazyDynamicInstance { |
210 typedef LazyInstanceImpl<T, DynamicallyAllocatedInstanceTrait<T>, CreateTrait, | 216 typedef LazyInstanceImpl<T, DynamicallyAllocatedInstanceTrait<T>, CreateTrait, |
211 DestroyTrait> type; | 217 DestroyTrait> type; |
212 }; | 218 }; |
213 | 219 |
214 } } // namespace v8::internal | 220 } } // namespace v8::internal |
215 | 221 |
216 #endif // V8_LAZY_INSTANCE_H_ | 222 #endif // V8_LAZY_INSTANCE_H_ |
OLD | NEW |