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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 | 104 |
105 | 105 |
106 template <typename T> | 106 template <typename T> |
107 struct LeakyInstanceTrait { | 107 struct LeakyInstanceTrait { |
108 static void Destroy(T* /* instance */) {} | 108 static void Destroy(T* /* instance */) {} |
109 }; | 109 }; |
110 | 110 |
111 | 111 |
112 // Traits that define how an instance is allocated and accessed. | 112 // Traits that define how an instance is allocated and accessed. |
113 | 113 |
| 114 // TODO(kalmard): __alignof__ is only defined for GCC > 4.2. Fix alignment issue |
| 115 // on MIPS with other compilers. |
| 116 #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 2)) |
| 117 #define LAZY_ALIGN(x) __attribute__((aligned(__alignof__(x)))) |
| 118 #else |
| 119 #define LAZY_ALIGN(x) |
| 120 #endif |
| 121 |
114 template <typename T> | 122 template <typename T> |
115 struct StaticallyAllocatedInstanceTrait { | 123 struct StaticallyAllocatedInstanceTrait { |
116 typedef char StorageType[sizeof(T)] V8_ALIGNAS(V8_ALIGNOF(T)); | 124 typedef char StorageType[sizeof(T)] LAZY_ALIGN(T); |
117 | 125 |
118 static T* MutableInstance(StorageType* storage) { | 126 static T* MutableInstance(StorageType* storage) { |
119 return reinterpret_cast<T*>(storage); | 127 return reinterpret_cast<T*>(storage); |
120 } | 128 } |
121 | 129 |
122 template <typename ConstructTrait> | 130 template <typename ConstructTrait> |
123 static void InitStorageUsingTrait(StorageType* storage) { | 131 static void InitStorageUsingTrait(StorageType* storage) { |
124 ConstructTrait::Construct(MutableInstance(storage)); | 132 ConstructTrait::Construct(MutableInstance(storage)); |
125 } | 133 } |
126 }; | 134 }; |
127 | 135 |
| 136 #undef LAZY_ALIGN |
| 137 |
128 | 138 |
129 template <typename T> | 139 template <typename T> |
130 struct DynamicallyAllocatedInstanceTrait { | 140 struct DynamicallyAllocatedInstanceTrait { |
131 typedef T* StorageType; | 141 typedef T* StorageType; |
132 | 142 |
133 static T* MutableInstance(StorageType* storage) { | 143 static T* MutableInstance(StorageType* storage) { |
134 return *storage; | 144 return *storage; |
135 } | 145 } |
136 | 146 |
137 template <typename CreateTrait> | 147 template <typename CreateTrait> |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 typename InitOnceTrait = SingleThreadInitOnceTrait, | 254 typename InitOnceTrait = SingleThreadInitOnceTrait, |
245 typename DestroyTrait = LeakyInstanceTrait<T> > | 255 typename DestroyTrait = LeakyInstanceTrait<T> > |
246 struct LazyDynamicInstance { | 256 struct LazyDynamicInstance { |
247 typedef LazyInstanceImpl<T, DynamicallyAllocatedInstanceTrait<T>, | 257 typedef LazyInstanceImpl<T, DynamicallyAllocatedInstanceTrait<T>, |
248 CreateTrait, InitOnceTrait, DestroyTrait> type; | 258 CreateTrait, InitOnceTrait, DestroyTrait> type; |
249 }; | 259 }; |
250 | 260 |
251 } } // namespace v8::internal | 261 } } // namespace v8::internal |
252 | 262 |
253 #endif // V8_LAZY_INSTANCE_H_ | 263 #endif // V8_LAZY_INSTANCE_H_ |
OLD | NEW |