Skip to content

Commit e4debda

Browse files
authored
Merge pull request swiftlang#66305 from mikeash/dont-cache-malloc-default-zone
[Runtime] Don't cache malloc_default_zone.
2 parents c74fd07 + 007ac9a commit e4debda

File tree

1 file changed

+2
-17
lines changed

1 file changed

+2
-17
lines changed

stdlib/public/runtime/Heap.cpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,6 @@ static constexpr size_t MALLOC_ALIGN_MASK = alignof(std::max_align_t) - 1;
6060
static_assert(_swift_MinAllocationAlignment > MALLOC_ALIGN_MASK,
6161
"Swift's default alignment must exceed platform malloc mask.");
6262

63-
#if defined(__APPLE__) && SWIFT_STDLIB_HAS_DARWIN_LIBMALLOC
64-
static inline malloc_zone_t *DEFAULT_ZONE() {
65-
static malloc_zone_t *z = SWIFT_LAZY_CONSTANT(malloc_default_zone());
66-
return z;
67-
}
68-
#endif
69-
7063
// When alignMask == ~(size_t(0)), allocation uses the "default"
7164
// _swift_MinAllocationAlignment. This is different than calling swift_slowAlloc
7265
// with `alignMask == _swift_MinAllocationAlignment - 1` because it forces
@@ -91,11 +84,7 @@ void *swift::swift_slowAlloc(size_t size, size_t alignMask) {
9184
void *p;
9285
// This check also forces "default" alignment to use AlignedAlloc.
9386
if (alignMask <= MALLOC_ALIGN_MASK) {
94-
#if defined(__APPLE__) && SWIFT_STDLIB_HAS_DARWIN_LIBMALLOC
95-
p = malloc_zone_malloc(DEFAULT_ZONE(), size);
96-
#else
9787
p = malloc(size);
98-
#endif
9988
} else {
10089
size_t alignment = computeAlignment(alignMask);
10190
p = AlignedAlloc(size, alignment);
@@ -111,10 +100,10 @@ void *swift::swift_slowAllocTyped(size_t size, size_t alignMask,
111100
void *p;
112101
// This check also forces "default" alignment to use malloc_memalign().
113102
if (alignMask <= MALLOC_ALIGN_MASK) {
114-
p = malloc_type_zone_malloc(DEFAULT_ZONE(), size, typeId);
103+
p = malloc_type_malloc(size, typeId);
115104
} else {
116105
size_t alignment = computeAlignment(alignMask);
117-
p = malloc_type_zone_memalign(DEFAULT_ZONE(), alignment, size, typeId);
106+
p = malloc_type_aligned_alloc(alignment, size, typeId);
118107
}
119108
if (!p) swift::crash("Could not allocate memory.");
120109
return p;
@@ -141,11 +130,7 @@ void *swift::swift_slowAllocTyped(size_t size, size_t alignMask,
141130
// consistent with allocation with the same alignment.
142131
static void swift_slowDeallocImpl(void *ptr, size_t alignMask) {
143132
if (alignMask <= MALLOC_ALIGN_MASK) {
144-
#if defined(__APPLE__) && SWIFT_STDLIB_HAS_DARWIN_LIBMALLOC
145-
malloc_zone_free(DEFAULT_ZONE(), ptr);
146-
#else
147133
free(ptr);
148-
#endif
149134
} else {
150135
AlignedFree(ptr);
151136
}

0 commit comments

Comments
 (0)