Skip to content

Commit 886957a

Browse files
authored
Merge pull request #1099 from microsoft/dev2
merge main from dev2 to v2.2.4
2 parents d2e259c + f89e039 commit 886957a

35 files changed

+559
-329
lines changed

CMakeLists.txt

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|x64|amd64|AMD64)$" OR CMAKE_GENE
126126
set(MI_ARCH "x64")
127127
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64|arm64|armv[89].?|ARM64)$" OR CMAKE_GENERATOR_PLATFORM STREQUAL "ARM64" OR "arm64" IN_LIST CMAKE_OSX_ARCHITECTURES)
128128
set(MI_ARCH "arm64")
129-
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm|armv[34567]|ARM)$")
129+
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm|armv[34567].?|ARM)$")
130130
set(MI_ARCH "arm32")
131131
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(riscv|riscv32|riscv64)$")
132132
if(CMAKE_SIZEOF_VOID_P==4)
@@ -173,7 +173,8 @@ if(CMAKE_C_COMPILER_ID MATCHES "Intel")
173173
list(APPEND mi_cflags -Wall)
174174
endif()
175175

176-
if(CMAKE_C_COMPILER_ID MATCHES "MSVC|Intel")
176+
# force C++ compilation with msvc or clang-cl to use modern C++ atomics
177+
if(CMAKE_C_COMPILER_ID MATCHES "MSVC|Intel" OR MI_CLANG_CL)
177178
set(MI_USE_CXX "ON")
178179
endif()
179180

@@ -712,10 +713,12 @@ if (MI_BUILD_TESTS)
712713
target_compile_definitions(mimalloc-test-${TEST_NAME} PRIVATE ${mi_defines})
713714
target_compile_options(mimalloc-test-${TEST_NAME} PRIVATE ${mi_cflags})
714715
target_include_directories(mimalloc-test-${TEST_NAME} PRIVATE include)
715-
if(MI_BUILD_SHARED AND (MI_TRACK_ASAN OR MI_DEBUG_TSAN OR MI_DEBUG_UBSAN))
716+
if(MI_BUILD_STATIC AND NOT MI_DEBUG_TSAN)
717+
target_link_libraries(mimalloc-test-${TEST_NAME} PRIVATE mimalloc-static ${mi_libraries})
718+
elseif(MI_BUILD_SHARED)
716719
target_link_libraries(mimalloc-test-${TEST_NAME} PRIVATE mimalloc ${mi_libraries})
717720
else()
718-
target_link_libraries(mimalloc-test-${TEST_NAME} PRIVATE mimalloc-static ${mi_libraries})
721+
message(STATUS "cannot build TSAN tests without MI_BUILD_SHARED being enabled")
719722
endif()
720723
add_test(NAME test-${TEST_NAME} COMMAND mimalloc-test-${TEST_NAME})
721724
endforeach()
@@ -724,21 +727,19 @@ if (MI_BUILD_TESTS)
724727
if(MI_BUILD_SHARED AND NOT (MI_TRACK_ASAN OR MI_DEBUG_TSAN OR MI_DEBUG_UBSAN))
725728
add_executable(mimalloc-test-stress-dynamic test/test-stress.c)
726729
target_compile_definitions(mimalloc-test-stress-dynamic PRIVATE ${mi_defines} "USE_STD_MALLOC=1")
727-
if(WIN32)
728-
target_compile_definitions(mimalloc-test-stress-dynamic PRIVATE "MI_LINK_VERSION=1")
729-
endif()
730730
target_compile_options(mimalloc-test-stress-dynamic PRIVATE ${mi_cflags})
731731
target_include_directories(mimalloc-test-stress-dynamic PRIVATE include)
732-
target_link_libraries(mimalloc-test-stress-dynamic PRIVATE mimalloc ${mi_libraries}) # mi_version
733732
if(WIN32)
734-
add_test(NAME test-stress-dynamic COMMAND ${CMAKE_COMMAND} -E env MIMALLOC_SHOW_STATS=1 $<TARGET_FILE:mimalloc-test-stress-dynamic>)
733+
target_compile_definitions(mimalloc-test-stress-dynamic PRIVATE "MI_LINK_VERSION=1") # link mi_version
734+
target_link_libraries(mimalloc-test-stress-dynamic PRIVATE mimalloc ${mi_libraries}) # link mi_version
735+
add_test(NAME test-stress-dynamic COMMAND ${CMAKE_COMMAND} -E env MIMALLOC_VERBOSE=1 $<TARGET_FILE:mimalloc-test-stress-dynamic>)
735736
else()
736737
if(APPLE)
737738
set(LD_PRELOAD "DYLD_INSERT_LIBRARIES")
738739
else()
739740
set(LD_PRELOAD "LD_PRELOAD")
740741
endif()
741-
add_test(NAME test-stress-dynamic COMMAND ${CMAKE_COMMAND} -E env MIMALLOC_SHOW_STATS=1 ${LD_PRELOAD}=$<TARGET_FILE:mimalloc> $<TARGET_FILE:mimalloc-test-stress-dynamic>)
742+
add_test(NAME test-stress-dynamic COMMAND ${CMAKE_COMMAND} -E env MIMALLOC_VERBOSE=1 ${LD_PRELOAD}=$<TARGET_FILE:mimalloc> $<TARGET_FILE:mimalloc-test-stress-dynamic>)
742743
endif()
743744
endif()
744745
endif()

azure-pipelines.yml

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ jobs:
4040
BuildType: release
4141
cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release -A Win32
4242
MSBuildConfiguration: Release
43+
Debug Fixed TLS:
44+
BuildType: debug
45+
cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Debug -DMI_DEBUG_FULL=ON -DMI_WIN_USE_FIXED_TLS=ON
46+
MSBuildConfiguration: Debug
47+
Release Fixed TLS:
48+
BuildType: release
49+
cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release -DMI_WIN_USE_FIXED_TLS=ON
50+
MSBuildConfiguration: Release
4351
steps:
4452
- task: CMake@1
4553
inputs:
@@ -175,35 +183,6 @@ jobs:
175183
# Other OS versions (just debug mode)
176184
# ----------------------------------------------------------
177185

178-
- job:
179-
displayName: Windows 2019
180-
pool:
181-
vmImage:
182-
windows-2019
183-
strategy:
184-
matrix:
185-
Debug:
186-
BuildType: debug
187-
cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Debug -DMI_DEBUG_FULL=ON
188-
MSBuildConfiguration: Debug
189-
Release:
190-
BuildType: release
191-
cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release
192-
MSBuildConfiguration: Release
193-
steps:
194-
- task: CMake@1
195-
inputs:
196-
workingDirectory: $(BuildType)
197-
cmakeArgs: .. $(cmakeExtraArgs)
198-
- task: MSBuild@1
199-
inputs:
200-
solution: $(BuildType)/libmimalloc.sln
201-
configuration: '$(MSBuildConfiguration)'
202-
msbuildArguments: -m
203-
- script: ctest --verbose --timeout 240 -C $(MSBuildConfiguration)
204-
workingDirectory: $(BuildType)
205-
displayName: CTest
206-
207186
- job:
208187
displayName: Ubuntu 24.04
209188
pool:

cmake/mimalloc-config-version.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
set(mi_version_major 2)
22
set(mi_version_minor 2)
3-
set(mi_version_patch 3)
3+
set(mi_version_patch 5)
44
set(mi_version ${mi_version_major}.${mi_version_minor})
55

66
set(PACKAGE_VERSION ${mi_version})

contrib/docker/alpine-arm32v7/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# install from an image
22
# download first an appropriate tar.gz image into the current directory
3-
# from: <https://github.com/alpinelinux/docker-alpine/tree/edge/armv7>
3+
# from <https://github.com/alpinelinux/docker-alpine/tree/edge/armv7>
44
FROM scratch
55

66
# Substitute the image name that was downloaded
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# install from an image
2+
# download first an appropriate tar.gz image into the current directory
3+
# from <https://github.com/alpinelinux/docker-alpine/tree/edge/x86>
4+
FROM scratch
5+
6+
# Substitute the image name that was downloaded
7+
ADD alpine-minirootfs-20250108-x86.tar.gz /
8+
9+
# Install tools
10+
RUN apk add build-base make cmake
11+
RUN apk add git
12+
RUN apk add vim
13+
14+
RUN mkdir -p /home/dev
15+
WORKDIR /home/dev
16+
17+
# Get mimalloc
18+
RUN git clone https://github.com/microsoft/mimalloc -b dev2
19+
RUN mkdir -p mimalloc/out/release
20+
RUN mkdir -p mimalloc/out/debug
21+
22+
# Build mimalloc debug
23+
WORKDIR /home/dev/mimalloc/out/debug
24+
RUN cmake ../.. -DMI_DEBUG_FULL=ON
25+
# RUN make -j
26+
# RUN make test
27+
28+
CMD ["/bin/sh"]

contrib/vcpkg/portfile.cmake

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ vcpkg_from_github(
44
HEAD_REF master
55

66
# The "REF" can be a commit hash, branch name (dev2), or a version (v2.2.1).
7-
# REF "v${VERSION}"
8-
REF e2db21e9ba9fb9172b7b0aa0fe9b8742525e8774
7+
REF "v${VERSION}"
8+
# REF e2db21e9ba9fb9172b7b0aa0fe9b8742525e8774
99

1010
# The sha512 is the hash of the tar.gz bundle.
11-
# (To get the sha512, run `vcpkg install mimalloc[override] --overlay-ports=<dir of this file>` and copy the sha from the error message.)
12-
SHA512 8cbb601fdf8b46dd6a9c0d314d6da9d4960699853829e96d2470753867f90689fb4caeaf30d628943fd388670dc11902dbecc9cc7c329b99a510524a09bdb612
11+
# (To get the sha512, run `vcpkg install "mimalloc[override]" --overlay-ports=./contrib/vcpkg` and copy the sha from the error message.)
12+
SHA512 5218fcd3ad285687ed3f78b4651d7d3aee92b6f28e6c563a884975e654a43c94c4e5c02c5ed0322c3d3627d83d4843df2d2d8441f09aa18d00674ca9fd657345
1313
)
1414

1515
vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
@@ -19,6 +19,7 @@ vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
1919
secure MI_SECURE
2020
override MI_OVERRIDE
2121
optarch MI_OPT_ARCH
22+
nooptarch MI_NO_OPT_ARCH
2223
optsimd MI_OPT_SIMD
2324
xmalloc MI_XMALLOC
2425
asm MI_SEE_ASM

contrib/vcpkg/vcpkg.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mimalloc",
3-
"version": "2.2.2",
3+
"version": "2.2.4",
44
"port-version": 1,
55
"description": "Compact general purpose allocator with excellent performance",
66
"homepage": "https://github.com/microsoft/mimalloc",
@@ -35,6 +35,9 @@
3535
"optarch": {
3636
"description": "Use architecture specific optimizations (on x64: '-march=haswell;-mavx2', on arm64: '-march=armv8.1-a')"
3737
},
38+
"nooptarch": {
39+
"description": "Do _not_ use architecture specific optimizations (on x64: '-march=haswell;-mavx2', on arm64: '-march=armv8.1-a')"
40+
},
3841
"optsimd": {
3942
"description": "Allow use of SIMD instructions (avx2 or neon) (requires 'optarch' to be enabled)"
4043
},

ide/vs2022/mimalloc-test-stress.vcxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,8 @@
282282
</ClCompile>
283283
</ItemGroup>
284284
<ItemGroup>
285-
<ProjectReference Include="mimalloc-lib.vcxproj">
286-
<Project>{abb5eae7-b3e6-432e-b636-333449892ea6}</Project>
285+
<ProjectReference Include="mimalloc-override-dll.vcxproj">
286+
<Project>{abb5eae7-b3e6-432e-b636-333449892ea7}</Project>
287287
</ProjectReference>
288288
</ItemGroup>
289289
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

include/mimalloc.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ terms of the MIT license. A copy of the license can be found in the file
88
#ifndef MIMALLOC_H
99
#define MIMALLOC_H
1010

11-
#define MI_MALLOC_VERSION 223 // major + 2 digits minor
11+
#define MI_MALLOC_VERSION 225 // major + 2 digits minor
1212

1313
// ------------------------------------------------------
1414
// Compiler specific attributes
@@ -154,16 +154,20 @@ mi_decl_export void mi_stats_reset(void) mi_attr_noexcept;
154154
mi_decl_export void mi_stats_merge(void) mi_attr_noexcept;
155155
mi_decl_export void mi_stats_print(void* out) mi_attr_noexcept; // backward compatibility: `out` is ignored and should be NULL
156156
mi_decl_export void mi_stats_print_out(mi_output_fun* out, void* arg) mi_attr_noexcept;
157+
mi_decl_export void mi_thread_stats_print_out(mi_output_fun* out, void* arg) mi_attr_noexcept;
157158
mi_decl_export void mi_options_print(void) mi_attr_noexcept;
158159

160+
mi_decl_export void mi_process_info(size_t* elapsed_msecs, size_t* user_msecs, size_t* system_msecs,
161+
size_t* current_rss, size_t* peak_rss,
162+
size_t* current_commit, size_t* peak_commit, size_t* page_faults) mi_attr_noexcept;
163+
164+
165+
// Generally do not use the following as these are usually called automatically
159166
mi_decl_export void mi_process_init(void) mi_attr_noexcept;
167+
mi_decl_export void mi_cdecl mi_process_done(void) mi_attr_noexcept;
160168
mi_decl_export void mi_thread_init(void) mi_attr_noexcept;
161169
mi_decl_export void mi_thread_done(void) mi_attr_noexcept;
162-
mi_decl_export void mi_thread_stats_print_out(mi_output_fun* out, void* arg) mi_attr_noexcept;
163170

164-
mi_decl_export void mi_process_info(size_t* elapsed_msecs, size_t* user_msecs, size_t* system_msecs,
165-
size_t* current_rss, size_t* peak_rss,
166-
size_t* current_commit, size_t* peak_commit, size_t* page_faults) mi_attr_noexcept;
167171

168172
// -------------------------------------------------------------------------------------
169173
// Aligned allocation

include/mimalloc/atomic.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ static inline intptr_t mi_atomic_subi(_Atomic(intptr_t)*p, intptr_t sub);
111111
#define mi_atomic_cas_ptr_weak_release(tp,p,exp,des) mi_atomic_cas_weak_release(p,exp,(tp*)des)
112112
#define mi_atomic_cas_ptr_weak_acq_rel(tp,p,exp,des) mi_atomic_cas_weak_acq_rel(p,exp,(tp*)des)
113113
#define mi_atomic_cas_ptr_strong_release(tp,p,exp,des) mi_atomic_cas_strong_release(p,exp,(tp*)des)
114+
#define mi_atomic_cas_ptr_strong_acq_rel(tp,p,exp,des) mi_atomic_cas_strong_acq_rel(p,exp,(tp*)des)
114115
#define mi_atomic_exchange_ptr_relaxed(tp,p,x) mi_atomic_exchange_relaxed(p,(tp*)x)
115116
#define mi_atomic_exchange_ptr_release(tp,p,x) mi_atomic_exchange_release(p,(tp*)x)
116117
#define mi_atomic_exchange_ptr_acq_rel(tp,p,x) mi_atomic_exchange_acq_rel(p,(tp*)x)
@@ -120,6 +121,7 @@ static inline intptr_t mi_atomic_subi(_Atomic(intptr_t)*p, intptr_t sub);
120121
#define mi_atomic_cas_ptr_weak_release(tp,p,exp,des) mi_atomic_cas_weak_release(p,exp,des)
121122
#define mi_atomic_cas_ptr_weak_acq_rel(tp,p,exp,des) mi_atomic_cas_weak_acq_rel(p,exp,des)
122123
#define mi_atomic_cas_ptr_strong_release(tp,p,exp,des) mi_atomic_cas_strong_release(p,exp,des)
124+
#define mi_atomic_cas_ptr_strong_acq_rel(tp,p,exp,des) mi_atomic_cas_strong_acq_rel(p,exp,des)
123125
#define mi_atomic_exchange_ptr_relaxed(tp,p,x) mi_atomic_exchange_relaxed(p,x)
124126
#define mi_atomic_exchange_ptr_release(tp,p,x) mi_atomic_exchange_release(p,x)
125127
#define mi_atomic_exchange_ptr_acq_rel(tp,p,x) mi_atomic_exchange_acq_rel(p,x)
@@ -303,6 +305,7 @@ static inline bool mi_atomic_casi64_strong_acq_rel(volatile _Atomic(int64_t*)p,
303305
#define mi_atomic_cas_ptr_weak_release(tp,p,exp,des) mi_atomic_cas_weak_release((_Atomic(uintptr_t)*)(p),(uintptr_t*)exp,(uintptr_t)des)
304306
#define mi_atomic_cas_ptr_weak_acq_rel(tp,p,exp,des) mi_atomic_cas_weak_acq_rel((_Atomic(uintptr_t)*)(p),(uintptr_t*)exp,(uintptr_t)des)
305307
#define mi_atomic_cas_ptr_strong_release(tp,p,exp,des) mi_atomic_cas_strong_release((_Atomic(uintptr_t)*)(p),(uintptr_t*)exp,(uintptr_t)des)
308+
#define mi_atomic_cas_ptr_strong_acq_rel(tp,p,exp,des) mi_atomic_cas_strong_acq_rel((_Atomic(uintptr_t)*)(p),(uintptr_t*)exp,(uintptr_t)des)
306309
#define mi_atomic_exchange_ptr_relaxed(tp,p,x) (tp*)mi_atomic_exchange_relaxed((_Atomic(uintptr_t)*)(p),(uintptr_t)x)
307310
#define mi_atomic_exchange_ptr_release(tp,p,x) (tp*)mi_atomic_exchange_release((_Atomic(uintptr_t)*)(p),(uintptr_t)x)
308311
#define mi_atomic_exchange_ptr_acq_rel(tp,p,x) (tp*)mi_atomic_exchange_acq_rel((_Atomic(uintptr_t)*)(p),(uintptr_t)x)

0 commit comments

Comments
 (0)