15
15
// ===----------------------------------------------------------------------===//
16
16
17
17
#include " swift/Basic/Lazy.h"
18
+ #include " swift/Runtime/Concurrent.h"
18
19
#include " swift/Runtime/HeapObject.h"
19
20
#include " swift/Runtime/Heap.h"
20
21
#include " swift/Runtime/Metadata.h"
21
22
#include " swift/ABI/System.h"
22
23
#include " llvm/Support/MathExtras.h"
23
- #include " MetadataCache.h"
24
24
#include " Private.h"
25
25
#include " swift/Runtime/Debug.h"
26
26
#include < algorithm>
@@ -145,36 +145,36 @@ static void destroyGenericBox(HeapObject *o) {
145
145
metadata->getAllocAlignMask ());
146
146
}
147
147
148
- class BoxCacheEntry : public CacheEntry <BoxCacheEntry> {
148
+ class BoxCacheEntry {
149
149
public:
150
- FullMetadata<GenericBoxHeapMetadata> Metadata ;
150
+ FullMetadata<GenericBoxHeapMetadata> Data ;
151
151
152
- BoxCacheEntry (size_t numArguments )
153
- : Metadata {HeapMetadataHeader{{destroyGenericBox}, {nullptr }},
154
- GenericBoxHeapMetadata{MetadataKind::HeapGenericLocalVariable, 0 ,
155
- nullptr }} {
156
- assert (numArguments == 1 );
152
+ BoxCacheEntry (const Metadata *type )
153
+ : Data {HeapMetadataHeader{{destroyGenericBox}, {/* vwtable */ nullptr }},
154
+ GenericBoxHeapMetadata{MetadataKind::HeapGenericLocalVariable,
155
+ GenericBoxHeapMetadata::getHeaderOffset (type),
156
+ type}} {
157
157
}
158
158
159
- size_t getNumArguments () const {
160
- return 1 ;
159
+ long getKeyIntValueForDump () {
160
+ return reinterpret_cast < long >(Data. BoxedType ) ;
161
161
}
162
162
163
- static const char * getName () {
164
- return " BoxCache " ;
163
+ int compareWithKey ( const Metadata *type) const {
164
+ return comparePointers (type, Data. BoxedType ) ;
165
165
}
166
166
167
- FullMetadata<GenericBoxHeapMetadata> * getData ( ) {
168
- return &Metadata ;
167
+ static size_t getExtraAllocationSize ( const Metadata *key ) {
168
+ return 0 ;
169
169
}
170
- const FullMetadata<GenericBoxHeapMetadata> * getData () const {
171
- return &Metadata ;
170
+ size_t getExtraAllocationSize () const {
171
+ return 0 ;
172
172
}
173
173
};
174
174
175
175
} // end anonymous namespace
176
176
177
- static Lazy<MetadataCache< BoxCacheEntry> > Boxes;
177
+ static ConcurrentMap< BoxCacheEntry, false > Boxes;
178
178
179
179
SWIFT_CC (swift) SWIFT_RUNTIME_EXPORT
180
180
BoxPair::Return
@@ -186,20 +186,7 @@ SWIFT_CC(swift) SWIFT_RT_ENTRY_IMPL_VISIBILITY
186
186
extern "C"
187
187
BoxPair::Return SWIFT_RT_ENTRY_IMPL(swift_allocBox)(const Metadata *type) {
188
188
// Get the heap metadata for the box.
189
- auto &B = Boxes.get ();
190
- const void *typeArg = type;
191
- auto entry = B.findOrAdd (&typeArg, 1 , [&]() -> BoxCacheEntry* {
192
- // Create a new entry for the box.
193
- auto entry = BoxCacheEntry::allocate (B.getAllocator (), &typeArg, 1 , 0 );
194
-
195
- auto metadata = entry->getData ();
196
- metadata->Offset = GenericBoxHeapMetadata::getHeaderOffset (type);
197
- metadata->BoxedType = type;
198
-
199
- return entry;
200
- });
201
-
202
- auto metadata = entry->getData ();
189
+ auto metadata = &Boxes.getOrInsert (type).first ->Data ;
203
190
204
191
// Allocate and project the box.
205
192
auto allocation = SWIFT_RT_ENTRY_CALL (swift_allocObject)(
0 commit comments