You've already forked linux-packaging-mono
acceptance-tests
data
docs
external
Newtonsoft.Json
api-doc-tools
api-snapshot
aspnetwebstack
bdwgc
binary-reference-assemblies
bockbuild
boringssl
cecil
cecil-legacy
corefx
corert
helix-binaries
ikdasm
ikvm
illinker-test-assets
linker
llvm-project
clang
clang-tools-extra
compiler-rt
eng
libcxx
libcxxabi
cmake
fuzz
include
lib
src
test
libcxxabi
native
support
CMakeLists.txt
backtrace_test.pass.cpp
catch_array_01.pass.cpp
catch_array_02.pass.cpp
catch_class_01.pass.cpp
catch_class_02.pass.cpp
catch_class_03.pass.cpp
catch_class_04.pass.cpp
catch_const_pointer_nullptr.pass.cpp
catch_function_01.pass.cpp
catch_function_02.pass.cpp
catch_function_03.pass.cpp
catch_in_noexcept.pass.cpp
catch_member_data_pointer_01.pass.cpp
catch_member_function_pointer_01.pass.cpp
catch_member_function_pointer_02.pass.cpp
catch_member_pointer_nullptr.pass.cpp
catch_multi_level_pointer.pass.cpp
catch_pointer_nullptr.pass.cpp
catch_pointer_reference.pass.cpp
catch_ptr.pass.cpp
catch_ptr_02.pass.cpp
catch_reference_nullptr.pass.cpp
cxa_bad_cast.pass.cpp
cxa_bad_typeid.pass.cpp
cxa_thread_atexit_test.pass.cpp
dynamic_cast14.pass.cpp
dynamic_cast3.pass.cpp
dynamic_cast5.pass.cpp
dynamic_cast_stress.pass.cpp
exception_object_alignment.pass.cpp
incomplete_type.sh.cpp
inherited_exception.pass.cpp
lit.cfg
lit.site.cfg.in
noexception1.pass.cpp
noexception2.pass.cpp
noexception3.pass.cpp
noexception4.pass.cpp
test_aux_runtime.pass.cpp
test_aux_runtime_op_array_new.pass.cpp
test_demangle.pass.cpp.REMOVED.git-id
test_exception_address_alignment.pass.cpp
test_exception_storage.pass.cpp
test_fallback_malloc.pass.cpp
test_guard.pass.cpp
test_vector1.pass.cpp
test_vector2.pass.cpp
test_vector3.pass.cpp
testit
thread_local_destruction_order.pass.cpp
uncaught_exceptions.pass.cpp
unittest_demangle.pass.cpp
unwind_01.pass.cpp
unwind_02.pass.cpp
unwind_03.pass.cpp
unwind_04.pass.cpp
unwind_05.pass.cpp
unwind_06.pass.cpp
www
.arcconfig
.clang-format
.gitignore
CMakeLists.txt
CREDITS.TXT
LICENSE.TXT
libunwind
lld
lldb
llvm
nuget
openmp
polly
Directory.Build.props
Directory.Build.targets
NuGet.config
azure-pipelines.yml
build.cmd
build.sh
dir.common.props
global.json
llvm.proj
mxe-Win64.cmake.in
nuget-buildtasks
nunit-lite
roslyn-binaries
rx
xunit-binaries
how-to-bump-roslyn-binaries.md
ikvm-native
llvm
m4
man
mcs
mono
msvc
netcore
po
runtime
samples
scripts
support
tools
COPYING.LIB
LICENSE
Makefile.am
Makefile.in
NEWS
README.md
acinclude.m4
aclocal.m4
autogen.sh
code_of_conduct.md
compile
config.guess
config.h.in
config.rpath
config.sub
configure.REMOVED.git-id
configure.ac.REMOVED.git-id
depcomp
install-sh
ltmain.sh.REMOVED.git-id
missing
mkinstalldirs
mono-uninstalled.pc.in
test-driver
winconfig.h
190 lines
5.7 KiB
C++
190 lines
5.7 KiB
C++
//===--------------------- test_fallback_malloc.cpp -----------------------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
|
// Source Licenses. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include <iostream>
|
|
#include <deque>
|
|
|
|
#include <__threading_support>
|
|
|
|
typedef std::deque<void *> container;
|
|
|
|
// #define DEBUG_FALLBACK_MALLOC
|
|
#define INSTRUMENT_FALLBACK_MALLOC
|
|
#include "../src/fallback_malloc.cpp"
|
|
|
|
container alloc_series ( size_t sz ) {
|
|
container ptrs;
|
|
void *p;
|
|
|
|
while ( NULL != ( p = fallback_malloc ( sz )))
|
|
ptrs.push_back ( p );
|
|
return ptrs;
|
|
}
|
|
|
|
container alloc_series ( size_t sz, float growth ) {
|
|
container ptrs;
|
|
void *p;
|
|
|
|
while ( NULL != ( p = fallback_malloc ( sz ))) {
|
|
ptrs.push_back ( p );
|
|
sz *= growth;
|
|
}
|
|
|
|
return ptrs;
|
|
}
|
|
|
|
container alloc_series ( const size_t *first, size_t len ) {
|
|
container ptrs;
|
|
const size_t *last = first + len;
|
|
void * p;
|
|
|
|
for ( const size_t *iter = first; iter != last; ++iter ) {
|
|
if ( NULL == (p = fallback_malloc ( *iter )))
|
|
break;
|
|
ptrs.push_back ( p );
|
|
}
|
|
|
|
return ptrs;
|
|
}
|
|
|
|
void *pop ( container &c, bool from_end ) {
|
|
void *ptr;
|
|
if ( from_end ) {
|
|
ptr = c.back ();
|
|
c.pop_back ();
|
|
}
|
|
else {
|
|
ptr = c.front ();
|
|
c.pop_front ();
|
|
}
|
|
return ptr;
|
|
}
|
|
|
|
void exhaustion_test1 () {
|
|
container ptrs;
|
|
|
|
init_heap ();
|
|
std::cout << "Constant exhaustion tests" << std::endl;
|
|
|
|
// Delete in allocation order
|
|
ptrs = alloc_series ( 32 );
|
|
std::cout << "Allocated " << ptrs.size () << " 32 byte chunks" << std::endl;
|
|
print_free_list ();
|
|
for ( container::iterator iter = ptrs.begin (); iter != ptrs.end (); ++iter )
|
|
fallback_free ( *iter );
|
|
print_free_list ();
|
|
std::cout << "----" << std::endl;
|
|
|
|
// Delete in reverse order
|
|
ptrs = alloc_series ( 32 );
|
|
std::cout << "Allocated " << ptrs.size () << " 32 byte chunks" << std::endl;
|
|
for ( container::reverse_iterator iter = ptrs.rbegin (); iter != ptrs.rend (); ++iter )
|
|
fallback_free ( *iter );
|
|
print_free_list ();
|
|
std::cout << "----" << std::endl;
|
|
|
|
// Alternate deletions
|
|
ptrs = alloc_series ( 32 );
|
|
std::cout << "Allocated " << ptrs.size () << " 32 byte chunks" << std::endl;
|
|
while ( ptrs.size () > 0 )
|
|
fallback_free ( pop ( ptrs, ptrs.size () % 1 == 1 ));
|
|
print_free_list ();
|
|
}
|
|
|
|
void exhaustion_test2 () {
|
|
container ptrs;
|
|
init_heap ();
|
|
|
|
std::cout << "Growing exhaustion tests" << std::endl;
|
|
|
|
// Delete in allocation order
|
|
ptrs = alloc_series ( 32, 1.5 );
|
|
std::cout << "Allocated " << ptrs.size () << " { 32, 48, 72, 108, 162 ... } byte chunks" << std::endl;
|
|
print_free_list ();
|
|
for ( container::iterator iter = ptrs.begin (); iter != ptrs.end (); ++iter )
|
|
fallback_free ( *iter );
|
|
print_free_list ();
|
|
std::cout << "----" << std::endl;
|
|
|
|
// Delete in reverse order
|
|
print_free_list ();
|
|
ptrs = alloc_series ( 32, 1.5 );
|
|
std::cout << "Allocated " << ptrs.size () << " { 32, 48, 72, 108, 162 ... } byte chunks" << std::endl;
|
|
for ( container::reverse_iterator iter = ptrs.rbegin (); iter != ptrs.rend (); ++iter )
|
|
fallback_free ( *iter );
|
|
print_free_list ();
|
|
std::cout << "----" << std::endl;
|
|
|
|
// Alternate deletions
|
|
ptrs = alloc_series ( 32, 1.5 );
|
|
std::cout << "Allocated " << ptrs.size () << " { 32, 48, 72, 108, 162 ... } byte chunks" << std::endl;
|
|
while ( ptrs.size () > 0 )
|
|
fallback_free ( pop ( ptrs, ptrs.size () % 1 == 1 ));
|
|
print_free_list ();
|
|
|
|
}
|
|
|
|
void exhaustion_test3 () {
|
|
const size_t allocs [] = { 124, 60, 252, 60, 4 };
|
|
container ptrs;
|
|
init_heap ();
|
|
|
|
std::cout << "Complete exhaustion tests" << std::endl;
|
|
|
|
// Delete in allocation order
|
|
ptrs = alloc_series ( allocs, sizeof ( allocs ) / sizeof ( allocs[0] ));
|
|
std::cout << "Allocated " << ptrs.size () << " chunks" << std::endl;
|
|
print_free_list ();
|
|
for ( container::iterator iter = ptrs.begin (); iter != ptrs.end (); ++iter )
|
|
fallback_free ( *iter );
|
|
print_free_list ();
|
|
std::cout << "----" << std::endl;
|
|
|
|
// Delete in reverse order
|
|
print_free_list ();
|
|
ptrs = alloc_series ( allocs, sizeof ( allocs ) / sizeof ( allocs[0] ));
|
|
std::cout << "Allocated " << ptrs.size () << " chunks" << std::endl;
|
|
for ( container::reverse_iterator iter = ptrs.rbegin (); iter != ptrs.rend (); ++iter )
|
|
fallback_free ( *iter );
|
|
print_free_list ();
|
|
std::cout << "----" << std::endl;
|
|
|
|
// Alternate deletions
|
|
ptrs = alloc_series ( allocs, sizeof ( allocs ) / sizeof ( allocs[0] ));
|
|
std::cout << "Allocated " << ptrs.size () << " chunks" << std::endl;
|
|
while ( ptrs.size () > 0 )
|
|
fallback_free ( pop ( ptrs, ptrs.size () % 1 == 1 ));
|
|
print_free_list ();
|
|
|
|
}
|
|
|
|
|
|
int main () {
|
|
print_free_list ();
|
|
|
|
char *p = (char *) fallback_malloc ( 1024 ); // too big!
|
|
std::cout << "fallback_malloc ( 1024 ) --> " << (unsigned long ) p << std::endl;
|
|
print_free_list ();
|
|
|
|
p = (char *) fallback_malloc ( 32 );
|
|
std::cout << "fallback_malloc ( 32 ) --> " << (unsigned long) (p - heap) << std::endl;
|
|
if ( !is_fallback_ptr ( p ))
|
|
std::cout << "### p is not a fallback pointer!!" << std::endl;
|
|
|
|
print_free_list ();
|
|
fallback_free ( p );
|
|
print_free_list ();
|
|
|
|
std::cout << std::endl;
|
|
exhaustion_test1 (); std::cout << std::endl;
|
|
exhaustion_test2 (); std::cout << std::endl;
|
|
exhaustion_test3 (); std::cout << std::endl;
|
|
return 0;
|
|
}
|