├── .gitignore ├── LICENSE ├── README.md ├── autosetup.sh ├── autosetup ├── config.inc ├── packages │ ├── autoconf.inc │ ├── automake.inc │ ├── bash.inc │ ├── binutils-gold.inc │ ├── cmake.inc │ ├── coreutils.inc │ ├── libtool.inc │ ├── libunwind.inc │ ├── llvm.inc │ ├── m4.inc │ ├── make.inc │ ├── perl-packages.inc │ ├── perl.inc │ └── perlbrew.inc ├── passes │ ├── baseline-lto.inc │ ├── dangsan-stats.inc │ ├── dangsan.inc │ └── helper │ │ ├── lto.inc │ │ ├── reset.inc │ │ └── tcmalloc.inc ├── paths.inc └── targets │ ├── parsec │ ├── benchmarks.inc │ ├── build.inc │ ├── config.inc │ ├── init.inc │ └── run-dedup.py │ └── spec-cpu2006 │ ├── benchmarks.inc │ ├── build.inc │ ├── config.inc │ ├── init.inc │ └── measuremem.py ├── gperftools-metalloc ├── .gitignore ├── AUTHORS ├── COPYING ├── ChangeLog ├── Makefile.am ├── NEWS ├── README ├── README_windows.txt ├── TODO ├── autogen.sh ├── benchmark │ ├── malloc_bench.cc │ ├── run_benchmark.c │ └── run_benchmark.h ├── configure.ac ├── doc │ ├── cpuprofile-fileformat.html │ ├── cpuprofile.html │ ├── designstyle.css │ ├── heap-example1.png │ ├── heap_checker.html │ ├── heapprofile.html │ ├── index.html │ ├── overview.dot │ ├── overview.gif │ ├── pageheap.dot │ ├── pageheap.gif │ ├── pprof-test-big.gif │ ├── pprof-test.gif │ ├── pprof-vsnprintf-big.gif │ ├── pprof-vsnprintf.gif │ ├── pprof.1 │ ├── pprof.see_also │ ├── pprof_remote_servers.html │ ├── spanmap.dot │ ├── spanmap.gif │ ├── t-test1.times.txt │ ├── tcmalloc-opspercpusec.vs.threads.1024.bytes.png │ ├── tcmalloc-opspercpusec.vs.threads.128.bytes.png │ ├── tcmalloc-opspercpusec.vs.threads.131072.bytes.png │ ├── tcmalloc-opspercpusec.vs.threads.16384.bytes.png │ ├── tcmalloc-opspercpusec.vs.threads.2048.bytes.png │ ├── tcmalloc-opspercpusec.vs.threads.256.bytes.png │ ├── tcmalloc-opspercpusec.vs.threads.32768.bytes.png │ ├── tcmalloc-opspercpusec.vs.threads.4096.bytes.png │ ├── tcmalloc-opspercpusec.vs.threads.512.bytes.png │ ├── tcmalloc-opspercpusec.vs.threads.64.bytes.png │ ├── tcmalloc-opspercpusec.vs.threads.65536.bytes.png │ ├── tcmalloc-opspercpusec.vs.threads.8192.bytes.png │ ├── tcmalloc-opspersec.vs.size.1.threads.png │ ├── tcmalloc-opspersec.vs.size.12.threads.png │ ├── tcmalloc-opspersec.vs.size.16.threads.png │ ├── tcmalloc-opspersec.vs.size.2.threads.png │ ├── tcmalloc-opspersec.vs.size.20.threads.png │ ├── tcmalloc-opspersec.vs.size.3.threads.png │ ├── tcmalloc-opspersec.vs.size.4.threads.png │ ├── tcmalloc-opspersec.vs.size.5.threads.png │ ├── tcmalloc-opspersec.vs.size.8.threads.png │ ├── tcmalloc.html │ ├── threadheap.dot │ └── threadheap.gif ├── gperftools.sln ├── m4 │ ├── ac_have_attribute.m4 │ ├── acx_nanosleep.m4 │ ├── acx_pthread.m4 │ ├── compiler_characteristics.m4 │ ├── install_prefix.m4 │ ├── namespaces.m4 │ ├── pc_from_ucontext.m4 │ ├── program_invocation_name.m4 │ └── stl_namespace.m4 ├── packages │ ├── deb.sh │ ├── deb │ │ ├── README │ │ ├── changelog │ │ ├── compat │ │ ├── control │ │ ├── copyright │ │ ├── docs │ │ ├── libgperftools-dev.dirs │ │ ├── libgperftools-dev.install │ │ ├── libgperftools0.dirs │ │ ├── libgperftools0.install │ │ ├── libgperftools0.manpages │ │ └── rules │ ├── rpm.sh │ └── rpm │ │ └── rpm.spec ├── src │ ├── addressmap-inl.h │ ├── base │ │ ├── arm_instruction_set_select.h │ │ ├── atomicops-internals-arm-generic.h │ │ ├── atomicops-internals-arm-v6plus.h │ │ ├── atomicops-internals-gcc.h │ │ ├── atomicops-internals-linuxppc.h │ │ ├── atomicops-internals-macosx.h │ │ ├── atomicops-internals-mips.h │ │ ├── atomicops-internals-windows.h │ │ ├── atomicops-internals-x86.cc │ │ ├── atomicops-internals-x86.h │ │ ├── atomicops.h │ │ ├── basictypes.h │ │ ├── commandlineflags.h │ │ ├── dynamic_annotations.c │ │ ├── dynamic_annotations.h │ │ ├── elf_mem_image.cc │ │ ├── elf_mem_image.h │ │ ├── elfcore.h │ │ ├── googleinit.h │ │ ├── linux_syscall_support.h │ │ ├── linuxthreads.cc │ │ ├── linuxthreads.h │ │ ├── logging.cc │ │ ├── logging.h │ │ ├── low_level_alloc.cc │ │ ├── low_level_alloc.h │ │ ├── simple_mutex.h │ │ ├── spinlock.cc │ │ ├── spinlock.h │ │ ├── spinlock_internal.cc │ │ ├── spinlock_internal.h │ │ ├── spinlock_linux-inl.h │ │ ├── spinlock_posix-inl.h │ │ ├── spinlock_win32-inl.h │ │ ├── stl_allocator.h │ │ ├── sysinfo.cc │ │ ├── sysinfo.h │ │ ├── thread_annotations.h │ │ ├── thread_lister.c │ │ ├── thread_lister.h │ │ ├── vdso_support.cc │ │ └── vdso_support.h │ ├── central_freelist.cc │ ├── central_freelist.h │ ├── common.cc │ ├── common.h │ ├── config_for_unittests.h │ ├── debugallocation.cc │ ├── getenv_safe.h │ ├── getpc.h │ ├── google │ │ ├── heap-checker.h │ │ ├── heap-profiler.h │ │ ├── malloc_extension.h │ │ ├── malloc_extension_c.h │ │ ├── malloc_hook.h │ │ ├── malloc_hook_c.h │ │ ├── profiler.h │ │ ├── stacktrace.h │ │ └── tcmalloc.h │ ├── gperftools │ │ ├── heap-checker.h │ │ ├── heap-profiler.h │ │ ├── malloc_extension.h │ │ ├── malloc_extension_c.h │ │ ├── malloc_hook.h │ │ ├── malloc_hook_c.h │ │ ├── profiler.h │ │ ├── stacktrace.h │ │ └── tcmalloc.h.in │ ├── heap-checker-bcad.cc │ ├── heap-checker.cc │ ├── heap-profile-stats.h │ ├── heap-profile-table.cc │ ├── heap-profile-table.h │ ├── heap-profiler.cc │ ├── internal_logging.cc │ ├── internal_logging.h │ ├── libc_override.h │ ├── libc_override_gcc_and_weak.h │ ├── libc_override_glibc.h │ ├── libc_override_osx.h │ ├── libc_override_redefine.h │ ├── linked_list.h │ ├── malloc_extension.cc │ ├── malloc_hook-inl.h │ ├── malloc_hook.cc │ ├── malloc_hook_mmap_freebsd.h │ ├── malloc_hook_mmap_linux.h │ ├── maybe_threads.cc │ ├── maybe_threads.h │ ├── memfs_malloc.cc │ ├── memory_region_map.cc │ ├── memory_region_map.h │ ├── metadata_page_heap.cc │ ├── metadata_page_heap.h │ ├── packed-cache-inl.h │ ├── page_heap.cc │ ├── page_heap.h │ ├── page_heap_allocator.h │ ├── pagemap.h │ ├── pprof │ ├── profile-handler.cc │ ├── profile-handler.h │ ├── profiledata.cc │ ├── profiledata.h │ ├── profiler.cc │ ├── raw_printer.cc │ ├── raw_printer.h │ ├── sampler.cc │ ├── sampler.h │ ├── span.cc │ ├── span.h │ ├── stack_trace_table.cc │ ├── stack_trace_table.h │ ├── stacktrace.cc │ ├── stacktrace_arm-inl.h │ ├── stacktrace_generic-inl.h │ ├── stacktrace_impl_setup-inl.h │ ├── stacktrace_instrument-inl.h │ ├── stacktrace_libunwind-inl.h │ ├── stacktrace_powerpc-darwin-inl.h │ ├── stacktrace_powerpc-inl.h │ ├── stacktrace_powerpc-linux-inl.h │ ├── stacktrace_win32-inl.h │ ├── stacktrace_x86-inl.h │ ├── static_vars.cc │ ├── static_vars.h │ ├── symbolize.cc │ ├── symbolize.h │ ├── system-alloc.cc │ ├── system-alloc.h │ ├── tcmalloc.cc │ ├── tcmalloc.h │ ├── tcmalloc_guard.h │ ├── tests │ │ ├── addressmap_unittest.cc │ │ ├── atomicops_unittest.cc │ │ ├── current_allocated_bytes_test.cc │ │ ├── debugallocation_test.cc │ │ ├── debugallocation_test.sh │ │ ├── frag_unittest.cc │ │ ├── getpc_test.cc │ │ ├── heap-checker-death_unittest.sh │ │ ├── heap-checker_unittest.cc │ │ ├── heap-checker_unittest.sh │ │ ├── heap-profiler_unittest.cc │ │ ├── heap-profiler_unittest.sh │ │ ├── large_heap_fragmentation_unittest.cc │ │ ├── low_level_alloc_unittest.cc │ │ ├── malloc_extension_c_test.c │ │ ├── malloc_extension_test.cc │ │ ├── malloc_hook_test.cc │ │ ├── markidle_unittest.cc │ │ ├── maybe_threads_unittest.sh │ │ ├── memalign_unittest.cc │ │ ├── packed-cache_test.cc │ │ ├── page_heap_test.cc │ │ ├── pagemap_unittest.cc │ │ ├── profile-handler_unittest.cc │ │ ├── profiledata_unittest.cc │ │ ├── profiler_unittest.cc │ │ ├── profiler_unittest.sh │ │ ├── raw_printer_test.cc │ │ ├── realloc_unittest.cc │ │ ├── sampler_test.cc │ │ ├── sampling_test.cc │ │ ├── sampling_test.sh │ │ ├── simple_compat_test.cc │ │ ├── stack_trace_table_test.cc │ │ ├── stacktrace_unittest.cc │ │ ├── system-alloc_unittest.cc │ │ ├── tcmalloc_large_unittest.cc │ │ ├── tcmalloc_unittest.cc │ │ ├── tcmalloc_unittest.sh │ │ ├── testutil.cc │ │ ├── testutil.h │ │ └── thread_dealloc_unittest.cc │ ├── third_party │ │ └── valgrind.h │ ├── thread_cache.cc │ ├── thread_cache.h │ └── windows │ │ ├── TODO │ │ ├── addr2line-pdb.c │ │ ├── auto_testing_hook.h │ │ ├── config.h │ │ ├── get_mangled_names.cc │ │ ├── google │ │ └── tcmalloc.h │ │ ├── gperftools │ │ ├── tcmalloc.h │ │ └── tcmalloc.h.in │ │ ├── ia32_modrm_map.cc │ │ ├── ia32_opcode_map.cc │ │ ├── mingw.h │ │ ├── mini_disassembler.cc │ │ ├── mini_disassembler.h │ │ ├── mini_disassembler_types.h │ │ ├── nm-pdb.c │ │ ├── override_functions.cc │ │ ├── patch_functions.cc │ │ ├── port.cc │ │ ├── port.h │ │ ├── preamble_patcher.cc │ │ ├── preamble_patcher.h │ │ ├── preamble_patcher_test.cc │ │ ├── preamble_patcher_with_stub.cc │ │ ├── shortproc.asm │ │ └── system-alloc.cc └── vsprojects │ ├── addr2line-pdb │ └── addr2line-pdb.vcproj │ ├── addressmap_unittest │ └── addressmap_unittest.vcproj │ ├── current_allocated_bytes_test │ └── current_allocated_bytes_test.vcproj │ ├── frag_unittest │ └── frag_unittest.vcproj │ ├── libtcmalloc_minimal │ └── libtcmalloc_minimal.vcproj │ ├── low_level_alloc_unittest │ └── low_level_alloc_unittest.vcproj │ ├── malloc_extension_test │ └── malloc_extension_test.vcproj │ ├── malloc_hook_test │ └── malloc_hook_test.vcproj │ ├── markidle_unittest │ └── markidle_unittest.vcproj │ ├── nm-pdb │ └── nm-pdb.vcproj │ ├── packed-cache_test │ └── packed-cache_test.vcproj │ ├── page_heap_test │ └── page_heap_test.vcproj │ ├── pagemap_unittest │ └── pagemap_unittest.vcproj │ ├── preamble_patcher_test │ └── preamble_patcher_test.vcproj │ ├── realloc_unittest │ └── realloc_unittest.vcproj │ ├── sampler_test │ └── sampler_test.vcproj │ ├── stack_trace_table_test │ └── stack_trace_table_test.vcproj │ ├── system-alloc_unittest │ └── system-alloc_unittest.vcproj │ ├── tcmalloc_minimal_large │ └── tcmalloc_minimal_large_unittest.vcproj │ ├── tcmalloc_minimal_unittest │ └── tcmalloc_minimal_unittest.vcproj │ ├── thread_dealloc_unittest │ └── thread_dealloc_unittest.vcproj │ └── tmu-static │ └── tmu-static.vcproj ├── llvm-plugins ├── .gitignore ├── ByvalHandler.cpp ├── CustomInliner.cpp ├── FreeSentry.cpp ├── FreeSentry.h ├── GlobalTracker.cpp ├── Makefile ├── PointerLoopTracker.cpp ├── PointerTracker.cpp ├── StackTracker.cpp ├── Utils.cpp └── Utils.h ├── metapagetable ├── .gitignore ├── Makefile ├── config_metapagetable.cmake ├── danghooks.c ├── defaulthooks.c ├── linker-options.in ├── metapagetable.c ├── metapagetable.h.in └── metapagetable_core.h ├── nothp ├── .gitignore ├── Makefile └── nothp.c ├── patches ├── COMPILERRT-safestack-3.8.diff ├── COMPILERRT-safestack-3.9.diff ├── GPERFTOOLS_SPEEDUP.patch ├── LLVM-gold-plugins-3.8.diff ├── LLVM-gold-plugins-3.9.diff ├── LLVM-safestack-3.8.diff ├── SPEC-CPU2006-dealII-stddef.patch ├── SPEC-CPU2006-soplex-dangsan-mask.patch ├── perl-makedepend.patch └── perl-pagesize.patch ├── scripts └── analyze-logs.py └── staticlib ├── .gitignore ├── Dangling ├── .gitignore ├── README ├── dang_san.c ├── dang_san.h ├── dang_san_cpp.c ├── dsan_atomics.h ├── dsan_common.h ├── dsan_stats.h └── dsan_stats_fields.h ├── Makefile ├── compat.c ├── globalinit.c ├── metadata.h ├── metadata_init.h ├── metaget.c ├── metaset.c └── stackinit.c /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.swp 3 | gperftools/* 4 | /autosetup.dir/ 5 | /run-*.sh 6 | -------------------------------------------------------------------------------- /autosetup/config.inc: -------------------------------------------------------------------------------- 1 | source "$PATHROOT/autosetup/targets/parsec/benchmarks.inc" # BENCHMARKS_PARSEC 2 | source "$PATHROOT/autosetup/targets/spec-cpu2006/benchmarks.inc" # BENCHMARKS_SPEC 3 | 4 | : ${INSTANCES=dangsan dangsan-stats baseline-lto} 5 | : ${INSTANCESUFFIX=} 6 | : ${JOBSMAX=16} 7 | : ${TARGETS=parsec spec-cpu2006} 8 | : ${THREADCOUNTS:="1 2 4 8 16 32 64"} 9 | -------------------------------------------------------------------------------- /autosetup/packages/autoconf.inc: -------------------------------------------------------------------------------- 1 | echo "building autoconf" 2 | cd "$PATHAUTOPACKSRC" 3 | [ -f "$VERSIONAUTOCONF.tar.gz" ] || run wget "http://ftp.gnu.org/gnu/autoconf/$VERSIONAUTOCONF.tar.gz" 4 | [ -d "$VERSIONAUTOCONF" ] || run tar xf "$VERSIONAUTOCONF.tar.gz" 5 | run mkdir -p "$PATHAUTOPACKOBJ/$VERSIONAUTOCONF" 6 | cd "$PATHAUTOPACKOBJ/$VERSIONAUTOCONF" 7 | [ -f Makefile ] || run "$PATHAUTOPACKSRC/$VERSIONAUTOCONF/configure" --prefix="$PATHAUTOPREFIX" 8 | run make -j"$JOBS" 9 | run make install 10 | -------------------------------------------------------------------------------- /autosetup/packages/automake.inc: -------------------------------------------------------------------------------- 1 | echo "building automake" 2 | cd "$PATHAUTOPACKSRC" 3 | [ -f "$VERSIONAUTOMAKE.tar.gz" ] || run wget "http://ftp.gnu.org/gnu/automake/$VERSIONAUTOMAKE.tar.gz" 4 | [ -d "$VERSIONAUTOMAKE" ] || run tar xf "$VERSIONAUTOMAKE.tar.gz" 5 | run mkdir -p "$PATHAUTOPACKOBJ/$VERSIONAUTOMAKE" 6 | cd "$PATHAUTOPACKOBJ/$VERSIONAUTOMAKE" 7 | [ -f Makefile ] || run "$PATHAUTOPACKSRC/$VERSIONAUTOMAKE/configure" --prefix="$PATHAUTOPREFIX" 8 | run make -j"$JOBS" 9 | run make install 10 | -------------------------------------------------------------------------------- /autosetup/packages/bash.inc: -------------------------------------------------------------------------------- 1 | echo "building bash" 2 | cd "$PATHAUTOPACKSRC" 3 | [ -f "$VERSIONBASH.tar.gz" ] || run wget "http://ftp.gnu.org/gnu/bash/$VERSIONBASH.tar.gz" 4 | [ -d "$VERSIONBASH" ] || run tar xf "$VERSIONBASH.tar.gz" 5 | run mkdir -p "$PATHAUTOPACKOBJ/$VERSIONBASH" 6 | cd "$PATHAUTOPACKOBJ/$VERSIONBASH" 7 | [ -f Makefile ] || run "$PATHAUTOPACKSRC/$VERSIONBASH/configure" --prefix="$PATHAUTOPREFIX" 8 | run make -j"$JOBS" 9 | run make install 10 | [ -h "$PATHAUTOPREFIX/bin/sh" ] || run ln -s "$PATHAUTOPREFIX/bin/bash" "$PATHAUTOPREFIX/bin/sh" 11 | -------------------------------------------------------------------------------- /autosetup/packages/binutils-gold.inc: -------------------------------------------------------------------------------- 1 | echo "building binutils" 2 | cd "$PATHAUTOPACKSRC" 3 | [ -f "$VERSIONBINUTILS.tar.bz2" ] || run wget "http://ftp.gnu.org/gnu/binutils/$VERSIONBINUTILS.tar.bz2" 4 | [ -d "$VERSIONBINUTILS" ] || run tar xf "$VERSIONBINUTILS.tar.bz2" 5 | run mkdir -p "$PATHAUTOPACKOBJ/$VERSIONBINUTILS" 6 | cd "$PATHAUTOPACKOBJ/$VERSIONBINUTILS" 7 | confopts="--enable-gold --enable-plugins --disable-werror" 8 | [ -n "`gcc -print-sysroot`" ] && confopts="$confopts --with-sysroot" # match system setting to avoid 'this linker was not configured to use sysroots' error or failure to find libpthread.so 9 | [ -f Makefile ] || run "$PATHAUTOPACKSRC/$VERSIONBINUTILS/configure" --prefix="$PATHAUTOPREFIX" $confopts 10 | run make -j"$JOBS" 11 | run make -j"$JOBS" all-gold 12 | run make install 13 | run rm "$PATHAUTOPREFIX/bin/ld" 14 | run cp "$PATHAUTOPREFIX/bin/ld.gold" "$PATHAUTOPREFIX/bin/ld" # replace ld with gold 15 | -------------------------------------------------------------------------------- /autosetup/packages/cmake.inc: -------------------------------------------------------------------------------- 1 | echo "building cmake" 2 | cd "$PATHAUTOPACKSRC" 3 | [ -f "$VERSIONCMAKE.tar.gz" ] || run wget "https://cmake.org/files/$VERSIONCMAKEURL/$VERSIONCMAKE.tar.gz" 4 | [ -d "$VERSIONCMAKE" ] || run tar xf "$VERSIONCMAKE.tar.gz" 5 | mkdir -p "$PATHAUTOPACKOBJ/$VERSIONCMAKE" 6 | cd "$PATHAUTOPACKOBJ/$VERSIONCMAKE" 7 | [ -f Makefile ] || run "$PATHAUTOPACKSRC/$VERSIONCMAKE/configure" --prefix="$PATHAUTOPREFIX" 8 | run make -j"$JOBS" 9 | run make install -------------------------------------------------------------------------------- /autosetup/packages/coreutils.inc: -------------------------------------------------------------------------------- 1 | echo "building coreutils" 2 | cd "$PATHAUTOPACKSRC" 3 | [ -f "$VERSIONCOREUTILS.tar.xz" ] || run wget "http://ftp.gnu.org/gnu/coreutils/$VERSIONCOREUTILS.tar.xz" 4 | [ -d "$VERSIONCOREUTILS" ] || run tar xf "$VERSIONCOREUTILS.tar.xz" 5 | run mkdir -p "$PATHAUTOPACKOBJ/$VERSIONCOREUTILS" 6 | cd "$PATHAUTOPACKOBJ/$VERSIONCOREUTILS" 7 | [ -f Makefile ] || run "$PATHAUTOPACKSRC/$VERSIONCOREUTILS/configure" --prefix="$PATHAUTOPREFIX" 8 | run make -j"$JOBS" 9 | run make install 10 | -------------------------------------------------------------------------------- /autosetup/packages/libtool.inc: -------------------------------------------------------------------------------- 1 | echo "building libtool" 2 | cd "$PATHAUTOPACKSRC" 3 | [ -f "$VERSIONLIBTOOL.tar.gz" ] || run wget "http://ftp.gnu.org/gnu/libtool/$VERSIONLIBTOOL.tar.gz" 4 | [ -d "$VERSIONLIBTOOL" ] || run tar xf "$VERSIONLIBTOOL.tar.gz" 5 | run mkdir -p "$PATHAUTOPACKOBJ/$VERSIONLIBTOOL" 6 | cd "$PATHAUTOPACKOBJ/$VERSIONLIBTOOL" 7 | [ -f Makefile ] || run "$PATHAUTOPACKSRC/$VERSIONLIBTOOL/configure" --prefix="$PATHAUTOPREFIX" 8 | run make -j"$JOBS" 9 | run make install 10 | -------------------------------------------------------------------------------- /autosetup/packages/libunwind.inc: -------------------------------------------------------------------------------- 1 | echo "building libunwind" 2 | cd "$PATHAUTOPACKSRC" 3 | [ -f "$VERSIONLIBUNWIND.tar.gz" ] || run wget "http://download.savannah.gnu.org/releases/libunwind/$VERSIONLIBUNWIND.tar.gz" 4 | [ -d "$VERSIONLIBUNWIND" ] || run tar xf "$VERSIONLIBUNWIND.tar.gz" 5 | run mkdir -p "$PATHAUTOPACKOBJ/$VERSIONLIBUNWIND" 6 | cd "$PATHAUTOPACKOBJ/$VERSIONLIBUNWIND" 7 | [ -f Makefile ] || run "$PATHAUTOPACKSRC/$VERSIONLIBUNWIND/configure" --prefix="$PATHAUTOPREFIX" 8 | run make -j"$JOBS" 9 | run make install 10 | -------------------------------------------------------------------------------- /autosetup/packages/llvm.inc: -------------------------------------------------------------------------------- 1 | echo "building LLVM" 2 | cd "$PATHAUTOPACKSRC" 3 | [ -d llvm-svn/.svn ] || run svn co -r"$VERSIONLLVM" http://llvm.org/svn/llvm-project/llvm/trunk llvm-svn 4 | [ -d llvm-svn/tools/clang/.svn ] || run svn co -r"$VERSIONLLVM" http://llvm.org/svn/llvm-project/cfe/trunk llvm-svn/tools/clang 5 | [ -d llvm-svn/projects/compiler-rt/.svn ] || run svn co -r"$VERSIONLLVM" http://llvm.org/svn/llvm-project/compiler-rt/trunk llvm-svn/projects/compiler-rt 6 | cd "$PATHAUTOPACKSRC/llvm-svn/projects/compiler-rt" 7 | if [ ! -f .autosetup.patched-COMPILERRT-safestack ]; then 8 | run patch -p0 < "$PATHROOT/patches/COMPILERRT-safestack-$VERSIONLLVMPATCH.diff" 9 | touch .autosetup.patched-COMPILERRT-safestack 10 | fi 11 | cd "$PATHAUTOPACKSRC/llvm-svn" 12 | if [ ! -f .autosetup.patched-LLVM-gold-plugins ]; then 13 | run patch -p0 < "$PATHROOT/patches/LLVM-gold-plugins-$VERSIONLLVMPATCH.diff" 14 | touch .autosetup.patched-LLVM-gold-plugins 15 | fi 16 | if [ ! -f .autosetup.patched-LLVM-safestack ]; then 17 | run patch -p0 < "$PATHROOT/patches/LLVM-safestack-$VERSIONLLVMPATCH.diff" 18 | touch .autosetup.patched-LLVM-safestack 19 | fi 20 | run mkdir -p "$PATHAUTOPACKSRC/llvm-svn/obj" 21 | cd "$PATHAUTOPACKSRC/llvm-svn/obj" 22 | [ -f Makefile ] || run cmake -DCMAKE_INSTALL_PREFIX="$PATHAUTOPREFIX" -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_BINUTILS_INCDIR="$PATHBINUTILS/include" "$PATHAUTOPACKSRC/llvm-svn" 23 | run make -j"$JOBS" 24 | run make install 25 | -------------------------------------------------------------------------------- /autosetup/packages/m4.inc: -------------------------------------------------------------------------------- 1 | echo "building m4" 2 | cd "$PATHAUTOPACKSRC" 3 | [ -f "$VERSIONM4.tar.gz" ] || run wget "http://ftp.gnu.org/gnu/m4/$VERSIONM4.tar.gz" 4 | [ -d "$VERSIONM4" ] || run tar xf "$VERSIONM4.tar.gz" 5 | run mkdir -p "$PATHAUTOPACKOBJ/$VERSIONM4" 6 | cd "$PATHAUTOPACKOBJ/$VERSIONM4" 7 | [ -f Makefile ] || run "$PATHAUTOPACKSRC/$VERSIONM4/configure" --prefix="$PATHAUTOPREFIX" 8 | run make -j"$JOBS" 9 | run make install 10 | -------------------------------------------------------------------------------- /autosetup/packages/make.inc: -------------------------------------------------------------------------------- 1 | echo "building make" 2 | cd "$PATHAUTOPACKSRC" 3 | [ -f "$VERSIONMAKE.tar.gz" ] || run wget "http://ftp.gnu.org/gnu/make/$VERSIONMAKE.tar.gz" 4 | [ -d "$VERSIONMAKE" ] || run tar xf "$VERSIONMAKE.tar.gz" 5 | run mkdir -p "$PATHAUTOPACKOBJ/$VERSIONMAKE" 6 | cd "$PATHAUTOPACKOBJ/$VERSIONMAKE" 7 | [ -f Makefile ] || run "$PATHAUTOPACKSRC/$VERSIONMAKE/configure" --prefix="$PATHAUTOPREFIX" 8 | run make -j"$JOBS" 9 | run make install 10 | -------------------------------------------------------------------------------- /autosetup/packages/perl-packages.inc: -------------------------------------------------------------------------------- 1 | echo "installing perl packages" 2 | if [ ! -f "$PATHAUTOSTATE/installed-perlbrew-perl-5.8.8" ]; then 3 | run perlbrew --notest install 5.8.8 4 | touch "$PATHAUTOSTATE/installed-perlbrew-perl-5.8.8" 5 | fi 6 | run perlbrew switch 5.8.8 7 | 8 | if [ "$NO_PERL" -eq 0 ]; then 9 | [ -f "$PERLBREW_ROOT/bin/cpanm" ] || run perlbrew install-cpanm 10 | run cpanm -n IO::Uncompress::Bunzip2 11 | run cpanm -n LWP::UserAgent 12 | run cpanm -n XML::SAX 13 | run cpanm -n IO::Scalar 14 | run cpanm -n Digest::MD5 15 | fi 16 | -------------------------------------------------------------------------------- /autosetup/packages/perl.inc: -------------------------------------------------------------------------------- 1 | echo "configuring perl" 2 | cd "$PATHAUTOPACKSRC" 3 | [ -f "$VERSIONPERL.tar.gz" ] || run wget "http://www.cpan.org/src/$VERSIONPERLURL/$VERSIONPERL.tar.gz" 4 | [ -d "$VERSIONPERL" ] || run tar xf "$VERSIONPERL.tar.gz" 5 | cd "$VERSIONPERL" 6 | PATHPERLPATCHES="$PATHROOT/patches" 7 | if [ ! -f .autosetup.patched-makedepend ]; then 8 | run patch -p1 < "$PATHPERLPATCHES/perl-makedepend.patch" 9 | touch .autosetup.patched-makedepend 10 | fi 11 | if [ ! -f .autosetup.patched-pagesize ]; then 12 | run patch -p1 < "$PATHPERLPATCHES/perl-pagesize.patch" 13 | touch .autosetup.patched-pagesize 14 | fi 15 | if [ ! -f .autosetup.patched-Configure ]; then 16 | libfile="`gcc -print-file-name=libm.so`" 17 | libpath="`dirname "$libfile"`" 18 | [ "$libpath" == . ] || sed -i "s|^xlibpth='|xlibpth='$libpath |" Configure 19 | touch .autosetup.patched-Configure 20 | fi 21 | 22 | if [ "$NO_PERL" -eq 0 ]; then 23 | echo "building perl" 24 | [ -f Makefile ] || run "$PATHAUTOPREFIX/bin/bash" ./Configure -des -Dprefix="$PATHAUTOPREFIX" 25 | for m in makefile x2p/makefile; do 26 | grep -v "" "$m" > "$m.tmp" 27 | mv "$m.tmp" "$m" 28 | done 29 | sed -i 's,# *include *,#define PAGE_SIZE 4096,' ext/IPC/SysV/SysV.xs 30 | run make -j"$JOBS" 31 | run make install 32 | fi 33 | -------------------------------------------------------------------------------- /autosetup/packages/perlbrew.inc: -------------------------------------------------------------------------------- 1 | echo "configuring perlbrew" 2 | export PERLBREW_ROOT="$PATHAUTOSETUP/perl-root" 3 | export PERLBREW_HOME="$PATHAUTOSETUP/perl-home" 4 | 5 | if [ "$NO_PERL" -eq 0 ]; then 6 | echo "building perlbrew" 7 | run mkdir -p "$PATHAUTOPACKSRC/perlbrew" 8 | cd "$PATHAUTOPACKSRC/perlbrew" 9 | [ -f perlbrew-installer ] || run wget -O perlbrew-installer http://install.perlbrew.pl 10 | [ -f perlbrew-installer-patched ] || sed "s,/usr/bin/perl,$PATHAUTOPREFIX/bin/perl,g" perlbrew-installer > perlbrew-installer-patched 11 | run chmod u+x perlbrew-installer-patched 12 | run "$PATHAUTOPREFIX/bin/bash" ./perlbrew-installer-patched 13 | fi 14 | 15 | source "$PERLBREW_ROOT/etc/bashrc" 16 | export PATH="$PERLBREW_ROOT/perls/perl-5.8.8/bin:$PATH" 17 | -------------------------------------------------------------------------------- /autosetup/passes/baseline-lto.inc: -------------------------------------------------------------------------------- 1 | source "$PATHROOT/autosetup/passes/helper/reset.inc" 2 | 3 | # tcmalloc settings 4 | CONFIG_MALLOC=tcmalloc 5 | 6 | # compiler settings 7 | cflags="$cflags -flto" 8 | ldflagsalways="$ldflagsalways -flto" 9 | 10 | source "$PATHROOT/autosetup/passes/helper/tcmalloc.inc" 11 | -------------------------------------------------------------------------------- /autosetup/passes/dangsan-stats.inc: -------------------------------------------------------------------------------- 1 | source "$PATHROOT/autosetup/passes/dangsan.inc" 2 | 3 | CONFIG_STATICLIB_MAKE="$CONFIG_STATICLIB_MAKE DANG_STATS=1" 4 | -------------------------------------------------------------------------------- /autosetup/passes/dangsan.inc: -------------------------------------------------------------------------------- 1 | source "$PATHROOT/autosetup/passes/helper/reset.inc" 2 | source "$PATHROOT/autosetup/passes/helper/lto.inc" 3 | 4 | # tcmalloc settings 5 | CONFIG_MALLOC=tcmalloc-metalloc 6 | CONFIG_FIXEDCOMPRESSION=false 7 | CONFIG_METADATABYTES=8 8 | CONFIG_DEEPMETADATA=false 9 | CONFIG_DEEPMETADATABYTES=128 10 | CONFIG_SAFESTACK_OPTIONS="largestack=true" 11 | CONFIG_ALLOC_SIZE_HOOK=dang_alloc_size_hook 12 | 13 | # safestack 14 | cflags="$cflags -fsanitize=safe-stack" 15 | ldflagsalways="$ldflagsalways -fsanitize=safe-stack" 16 | 17 | # passes 18 | add_lto_args -largestack=false 19 | add_lto_args -stats 20 | add_lto_args -mergedstack=false 21 | add_lto_args -byvalhandler 22 | add_lto_args -stacktracker 23 | add_lto_args -globaltracker 24 | add_lto_args -pointertracker 25 | add_lto_args -FreeSentryLoop 26 | add_lto_args -custominline 27 | 28 | # The linker does not include these symbols unless we explicitly say so 29 | ldflagsalways="$ldflagsalways -umetaget_$CONFIG_METADATABYTES" 30 | ldflagsalways="$ldflagsalways -umetaset_$CONFIG_METADATABYTES" 31 | ldflagsalways="$ldflagsalways -umetacheck_$CONFIG_METADATABYTES" 32 | ldflagsalways="$ldflagsalways -umetaset_alignment_safe_$CONFIG_METADATABYTES" 33 | ldflagsalways="$ldflagsalways -umetaset_$CONFIG_METADATABYTES" 34 | ldflagsalways="$ldflagsalways -uinitialize_global_metadata" 35 | 36 | ldflagsnolib="$ldflagsnolib -L$PATHAUTOFRAMEWORKOBJ/staticlib-$instance" 37 | ldflagsnolib="$ldflagsnolib -Wl,-whole-archive,-l:libmetadata.a,-no-whole-archive" 38 | ldflagslib="$ldflagslib $PATHAUTOFRAMEWORKOBJ/staticlib-$instance/globalinit.o" 39 | ldflagsalways="$ldflagsalways -ldl" 40 | ldflagsalways="$ldflagsalways @$PATHAUTOFRAMEWORKOBJ/metapagetable-$instance/linker-options" 41 | 42 | source "$PATHROOT/autosetup/passes/helper/tcmalloc.inc" 43 | -------------------------------------------------------------------------------- /autosetup/passes/helper/lto.inc: -------------------------------------------------------------------------------- 1 | cflags="$cflags -flto" 2 | ldflagsalways="$ldflagsalways -flto -Wl,-plugin-opt=-load=$PATHLLVMPLUGINS/libplugins.so" 3 | 4 | # helper for pass config files 5 | add_lto_args() { 6 | for arg in "$@"; do 7 | ldflagsalways="$ldflagsalways -Wl,-plugin-opt=$arg" 8 | done 9 | } 10 | -------------------------------------------------------------------------------- /autosetup/passes/helper/reset.inc: -------------------------------------------------------------------------------- 1 | unset CONFIG_MALLOC 2 | unset CONFIG_FIXEDCOMPRESSION 3 | unset CONFIG_METADATABYTES 4 | unset CONFIG_DEEPMETADATA 5 | unset CONFIG_DEEPMETADATABYTES 6 | unset CONFIG_SAFESTACK_OPTIONS 7 | 8 | unset CONFIG_STATICLIB_MAKE 9 | 10 | ar="$PATHAUTOPREFIX/bin/llvm-ar" 11 | cc="$PATHAUTOPREFIX/bin/clang" 12 | cxx="$PATHAUTOPREFIX/bin/clang++" 13 | cflags="$EXTRA_CFLAGS" 14 | ldflagsalways="$EXTRA_LDFLAGS" 15 | ldflagsnolib="" 16 | ldflagslib="" 17 | nm="$PATHAUTOPREFIX/bin/llvm-nm" 18 | ranlib="$PATHAUTOPREFIX/bin/llvm-ranlib" 19 | blacklist="" 20 | run_wrapper="" 21 | post_build_hooks=() 22 | 23 | unset prefix 24 | unset prefixbin 25 | unset prefixlib 26 | -------------------------------------------------------------------------------- /autosetup/passes/helper/tcmalloc.inc: -------------------------------------------------------------------------------- 1 | prefix="$PATHAUTOPREFIXBASE/$instance" 2 | prefixbin="$prefix/bin" 3 | prefixlib="$prefix/lib" 4 | 5 | ldflagsalways="$ldflagsalways -ltcmalloc -lpthread -lunwind" 6 | ldflagsalways="$ldflagsalways -L$prefix/lib -L$PATHAUTOPREFIX/lib" 7 | -------------------------------------------------------------------------------- /autosetup/paths.inc: -------------------------------------------------------------------------------- 1 | : ${PATHAUTOSETUP="$PATHROOT/autosetup.dir"} 2 | : ${PATHAUTOPREFIXBASE="$PATHAUTOSETUP/install"} 3 | : ${PATHAUTOPREFIX="$PATHAUTOPREFIXBASE/common"} 4 | : ${PATHAUTOFRAMEWORKOBJ="$PATHAUTOSETUP/framework/obj"} 5 | : ${PATHAUTOFRAMEWORKSRC="$PATHAUTOSETUP/framework/src"} 6 | : ${PATHAUTOPACKOBJ="$PATHAUTOSETUP/packages/obj"} 7 | : ${PATHAUTOPACKSRC="$PATHAUTOSETUP/packages/src"} 8 | : ${PATHAUTOSCRIPTSBUILD="$PATHAUTOSETUP/scripts"} 9 | : ${PATHAUTOSCRIPTSRUN="$PATHROOT"} 10 | : ${PATHAUTOTARGETOBJ="$PATHAUTOSETUP/targets/obj"} 11 | : ${PATHAUTOTARGETSRC="$PATHAUTOSETUP/targets/src"} 12 | : ${PATHAUTOSTATE="$PATHAUTOSETUP/state"} 13 | : ${PATHLLVMPLUGINS="$PATHAUTOFRAMEWORKOBJ/llvm-plugins"} 14 | : ${PATHLOG="$PATHAUTOSETUP/logs/autosetup.txt"} 15 | # PATHSPEC must be set by the user 16 | -------------------------------------------------------------------------------- /autosetup/targets/parsec/benchmarks.inc: -------------------------------------------------------------------------------- 1 | BENCHMARKS_PARSEC_PARSEC=" 2 | parsec.blackscholes 3 | parsec.canneal 4 | parsec.ferret 5 | parsec.fluidanimate 6 | parsec.freqmine 7 | parsec.streamcluster 8 | parsec.vips 9 | parsec.x264 10 | " 11 | BENCHMARKS_PARSEC_SPLASH2=" 12 | splash2.barnes 13 | splash2.cholesky 14 | splash2.fft 15 | splash2.fmm 16 | splash2.lu_cb 17 | splash2.lu_ncb 18 | splash2.ocean_cp 19 | splash2.ocean_ncp 20 | splash2.radiosity 21 | splash2.radix 22 | splash2.raytrace 23 | splash2.volrend 24 | splash2.water_nsquared 25 | splash2.water_spatial 26 | " 27 | BENCHMARKS_PARSEC_SPLASH2X=" 28 | splash2x.barnes 29 | splash2x.cholesky 30 | splash2x.fft 31 | splash2x.fmm 32 | splash2x.lu_cb 33 | splash2x.lu_ncb 34 | splash2x.ocean_cp 35 | splash2x.ocean_ncp 36 | splash2x.radiosity 37 | splash2x.radix 38 | splash2x.raytrace 39 | splash2x.water_nsquared 40 | splash2x.water_spatial 41 | " 42 | 43 | # compile issues: 44 | # parsec.bodytrack incorrect template syntax for clang 45 | # parsec.cmake expects strlcat; fixed in dangsan but does not work with baseline 46 | # parsec.dedup incorrect pod2man syntax 47 | # parsec.facesim undeclared template used 48 | # parsec.mesa incorrect asm syntax 49 | # parsec.netdedup conflicting header files 50 | # parsec.netferret conflicting header files 51 | # parsec.netstreamcluster conflicting header files 52 | # parsec.raytrace incorrect asm syntax 53 | # parsec.ssl incorrect pod2man syntax 54 | # parsec.swaptions missing -I switch 55 | # parsec.uptcpip conflicting header files 56 | # splash2x.volrend incorrect main function, missing includes 57 | 58 | # not real benchmarks: 59 | # parsec.glib 60 | # parsec.gsl 61 | # parsec.hooks 62 | # parsec.libjpeg 63 | # parsec.libtool 64 | # parsec.libxml2 65 | # parsec.parmacs 66 | # parsec.tbblib 67 | # parsec.yasm 68 | # parsec.zlib 69 | 70 | : ${BENCHMARKS_PARSEC:="$BENCHMARKS_PARSEC_PARSEC $BENCHMARKS_PARSEC_SPLASH2X"} 71 | -------------------------------------------------------------------------------- /autosetup/targets/parsec/build.inc: -------------------------------------------------------------------------------- 1 | for benchmark in $BENCHMARKS_PARSEC; do 2 | echo "building parsec-$instancename $benchmark" 3 | logsuffix="parsec-$instancename-$benchmark" run time "$PATHAUTOSCRIPTSBUILD/build-parsec-$instancename.sh" -p "$benchmark" 4 | done 5 | -------------------------------------------------------------------------------- /autosetup/targets/parsec/config.inc: -------------------------------------------------------------------------------- 1 | cd "$PATHAUTOTARGETSRC/$VERSIONPARSEC" 2 | 3 | ccflto="" 4 | for arg in $cflagsbl; do 5 | if [ "-flto" = "$arg" ]; then 6 | ccflto="-flto" 7 | fi 8 | done 9 | 10 | configname="MetAlloc-$instancename" 11 | configpath="$PATHAUTOTARGETSRC/$VERSIONPARSEC/config/$configname.bldconf" 12 | 13 | pathwrappers="$PATHAUTOTARGETOBJ/$VERSIONPARSEC/binwrap/$configname" 14 | run mkdir -p "$pathwrappers/bin" 15 | makewrapper() 16 | { 17 | name="$1" 18 | shift 19 | ( 20 | echo "#!$PATHAUTOPREFIX/bin/bash" 21 | echo "set -e" 22 | echo "$PATHROOT/autosetup/targets/parsec/run-dedup.py $* \"\$@\"" 23 | ) > "$pathwrappers/bin/$name" 24 | chmod u+x "$pathwrappers/bin/$name" 25 | } 26 | makewrapper cc "$cc $ccflto" 27 | makewrapper c++ "$cxx $ccflto" 28 | makewrapper cpp "$cc -E" 29 | makewrapper gcc "$cc $ccflto" 30 | makewrapper g++ "$cxx $ccflto" 31 | makewrapper ar "$ar" 32 | makewrapper as "$PATHAUTOPREFIX/bin/llvm-as" 33 | makewrapper ld "$PATHAUTOPREFIX/bin/ld.gold -plugin $PATHAUTOPREFIX/lib/LLVMgold.so" 34 | makewrapper make "$PATHAUTOPREFIX/bin/make" 35 | makewrapper m4 "$PATHAUTOPREFIX/bin/m4" 36 | makewrapper ranlib "$ranlib" 37 | 38 | parsecsettingadd() 39 | { 40 | sed -i "s|^ *export $1=\"\\(.*\\)\"|export $1=\"\\1 $2\"|" "$configpath" 41 | } 42 | 43 | parsecsettingset() 44 | { 45 | sed -i "s|^ *export $1=.*|export $1=\"$2\"|" "$configpath" 46 | } 47 | 48 | bin/bldconfadd -n "$configname" -c gcc -f 49 | parsecsettingset CC_HOME "$pathwrappers" 50 | parsecsettingset BINUTIL_HOME "$pathwrappers" 51 | parsecsettingset GNUTOOL_HOME "$pathwrappers" 52 | parsecsettingset BINARY_PREFIX "" 53 | parsecsettingset CC "$pathwrappers/bin/cc" 54 | parsecsettingset CXX "$pathwrappers/bin/c++" 55 | parsecsettingset CPP "$pathwrappers/bin/cpp" 56 | parsecsettingadd CFLAGS "$cflagsbl" 57 | parsecsettingadd CXXFLAGS "$cflagsbl" 58 | parsecsettingadd LDFLAGS "$ldflagsalways $ldflagsnolib" 59 | parsecsettingset AS "$pathwrappers/bin/as" 60 | parsecsettingset LD "$pathwrappers/bin/ld" 61 | parsecsettingset AR "$ar" 62 | parsecsettingset RANLIB "$ranlib" 63 | echo "export PATH=\"$pathwrappers/bin:\$PATH\"" >> "$configpath" 64 | 65 | for d in `find "$PATHAUTOTARGETSRC/$VERSIONPARSEC" -type d -name parsec`; do 66 | ( 67 | echo "#!/bin/bash" 68 | echo "source \"$d/gcc.bldconf\"" 69 | ) > "$d/$configname.bldconf" 70 | done 71 | 72 | scriptpathbuild="$PATHAUTOSCRIPTSBUILD/build-parsec-$instancename.sh" 73 | ( 74 | runscript_common_start 75 | echo "export V=1" 76 | echo "export VERBOSE=1" 77 | echo "" 78 | echo "cd \"$PATHAUTOTARGETSRC/$VERSIONPARSEC\"" 79 | echo "source env.sh" 80 | echo "bin/parsecmgmt -c \"$configname\" -a build \"\$@\"" 81 | runscript_common_end 82 | ) > "$scriptpathbuild" 83 | run chmod u+x "$scriptpathbuild" 84 | 85 | scriptpathrun="$PATHAUTOSCRIPTSRUN/run-parsec-$instancename.sh" 86 | ( 87 | runscript_common_start 88 | echo "cd \"$PATHAUTOTARGETSRC/$VERSIONPARSEC\"" 89 | echo ": \${PATHTEMP:=\"$PATHROOT/autosetup.tmp/\`uname -n\`.\$\$\"}" 90 | echo "mkdir -p \"\$PATHTEMP\"" 91 | echo "source env.sh" 92 | echo -n "\"$PATHROOT/nothp/nothp\" " 93 | echo "bin/parsecmgmt -c \"$configname\" -a run -d \"\$PATHTEMP\" \"\$@\"" 94 | echo "rm -rf \"\$PATHTEMP\"" 95 | runscript_common_end 96 | ) > "$scriptpathrun" 97 | run chmod u+x "$scriptpathrun" 98 | -------------------------------------------------------------------------------- /autosetup/targets/parsec/init.inc: -------------------------------------------------------------------------------- 1 | cd "$PATHAUTOTARGETSRC" 2 | [ -f "$VERSIONPARSEC.tar.gz" ] || run wget "http://parsec.cs.princeton.edu/download/$VERSIONPARSECURL/$VERSIONPARSEC.tar.gz" 3 | [ -d "$VERSIONPARSEC" ] || run tar xf "$VERSIONPARSEC.tar.gz" 4 | -------------------------------------------------------------------------------- /autosetup/targets/parsec/run-dedup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import os 4 | import sys 5 | 6 | def deduparg(arg): 7 | if arg.startswith("@"): return True 8 | if arg.startswith("-fsanitize="): return True 9 | if arg.startswith("-Wl,-plugin-opt="): return True 10 | if arg.startswith("-Wl,-l:") and arg.endswith(".a"): return True 11 | if arg == "-Wl,-whole-archive,-l:libmetadata.a,-no-whole-archive": return True 12 | return False 13 | 14 | def skiparg(arg): 15 | if arg == "-fno-rtti": return True 16 | return False 17 | 18 | args = list() 19 | argset = set() 20 | for arg in sys.argv[1:]: 21 | if skiparg(arg): continue 22 | if deduparg(arg) and (arg in argset): continue 23 | args.append(arg) 24 | argset.add(arg) 25 | 26 | os.execvp(args[0], args) 27 | 28 | -------------------------------------------------------------------------------- /autosetup/targets/spec-cpu2006/benchmarks.inc: -------------------------------------------------------------------------------- 1 | BENCHMARKS_SPEC_C=" 2 | 400.perlbench 3 | 401.bzip2 4 | 403.gcc 5 | 429.mcf 6 | 433.milc 7 | 445.gobmk 8 | 456.hmmer 9 | 458.sjeng 10 | 462.libquantum 11 | 464.h264ref 12 | 470.lbm 13 | 482.sphinx3 14 | " 15 | BENCHMARKS_SPEC_CPP=" 16 | 444.namd 17 | 447.dealII 18 | 450.soplex 19 | 453.povray 20 | 471.omnetpp 21 | 473.astar 22 | 483.xalancbmk 23 | " 24 | 25 | : ${BENCHMARKS_SPEC:="$BENCHMARKS_SPEC_C $BENCHMARKS_SPEC_CPP"} 26 | -------------------------------------------------------------------------------- /autosetup/targets/spec-cpu2006/build.inc: -------------------------------------------------------------------------------- 1 | for benchmark in $BENCHMARKS_SPEC; do 2 | echo "building spec-cpu2006-$instancename $benchmark" 3 | logsuffix="spec-cpu2006-$instancename-$benchmark" run time "$PATHAUTOSCRIPTSBUILD/build-spec-cpu2006-$instancename.sh" "$benchmark" 4 | done 5 | 6 | echo "updating spec-cpu2006-$instancename MD5s" 7 | configbuild="$PATHSPEC/config/MetAlloc-$instancename-build.cfg" 8 | configrun="$PATHSPEC/config/MetAlloc-$instancename-run.cfg" 9 | lineno="`grep -n __MD5__ "$configbuild" | cut -d: -f1`" 10 | tail -n "+$lineno" "$configbuild" >> "$configrun" 11 | -------------------------------------------------------------------------------- /autosetup/targets/spec-cpu2006/init.inc: -------------------------------------------------------------------------------- 1 | if [ -f "$PATHSPEC/shrc" ]; then 2 | echo "using existing SPEC CPU2006 installation" 3 | else 4 | echo "please set \$PATHSPEC to the root of your SPEC CPU2006 installation" >&2 5 | exit 1 6 | fi 7 | 8 | cd "$PATHSPEC" 9 | if [ ! -f .autosetup.patched-dealII-stddef ]; then 10 | run patch -p0 < "$PATHROOT/patches/SPEC-CPU2006-dealII-stddef.patch" 11 | touch .autosetup.patched-dealII-stddef 12 | fi 13 | if [ ! -f .autosetup.patched-soplex-dangsan-mask ]; then 14 | run patch -p0 < "$PATHROOT/patches/SPEC-CPU2006-soplex-dangsan-mask.patch" 15 | touch .autosetup.patched-soplex-dangsan-mask 16 | fi 17 | 18 | if [ "$VERSIONPERL" != none ]; then 19 | # build Perl, default perl does not work with perlbrew 20 | source "$PATHROOT/autosetup/packages/perl.inc" 21 | 22 | # install perlbrew (needed by SPEC CPU2006), fixing its installer in the process 23 | source "$PATHROOT/autosetup/packages/perlbrew.inc" 24 | 25 | # install perl packages 26 | source "$PATHROOT/autosetup/packages/perl-packages.inc" 27 | fi 28 | -------------------------------------------------------------------------------- /autosetup/targets/spec-cpu2006/measuremem.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import math 4 | import os 5 | import re 6 | import subprocess 7 | import sys 8 | 9 | def commandNew(argv, stdin, stdout, stderr): 10 | return (argv, stdin, stdout, stderr) 11 | 12 | def getRundir(specdir, instancename, benchmark): 13 | return "%s/benchspec/CPU2006/%s/run/run_base_ref_MetAlloc-%s.0000" % (specdir, benchmark, instancename) 14 | 15 | def commandGetArgv(command): 16 | return command[0] 17 | 18 | def commandGetStdin(command): 19 | return command[1] 20 | 21 | def getCommandFromLine(commands, line): 22 | stdin = "/dev/null" 23 | stderr = "/dev/null" 24 | stdout = "/dev/null" 25 | 26 | parts = line.split(" ") 27 | index = 0 28 | while index + 1 < len(parts) and len(parts[index]) > 1 and parts[index].startswith("-"): 29 | if parts[index] == "-C": 30 | return 31 | elif parts[index] == "-e": 32 | stderr = parts[index + 1] 33 | elif parts[index] == "-i": 34 | stdin = parts[index + 1] 35 | elif parts[index] == "-o": 36 | stdout = parts[index + 1] 37 | else: 38 | break 39 | index += 2 40 | 41 | if index >= len(parts): 42 | return 43 | 44 | commands.append(commandNew(parts[index:], stdin, stdout, stderr)) 45 | 46 | def getCommands(rundir): 47 | commands = list() 48 | commandsFilePath = "%s/speccmds.cmd" % (rundir) 49 | f = open(commandsFilePath, "r") 50 | for line in f: 51 | getCommandFromLine(commands, line.strip()) 52 | f.close() 53 | return commands 54 | 55 | def printfile(path, outfile): 56 | infile = open(path, "r") 57 | for line in infile: 58 | outfile.write("%s" % (line)) 59 | infile.close() 60 | 61 | def processbenchmark(specdir, instancename, benchmark): 62 | rundir = getRundir(specdir, instancename, benchmark) 63 | sys.stdout.write("run directory: %s\n" % (rundir)) 64 | os.chdir(rundir) 65 | 66 | temppath = "%s/timeoutput.%d.tmp" % (rundir, os.getpid()) 67 | 68 | commands = getCommands(rundir) 69 | for command in commands: 70 | timeCommand = list() 71 | timeCommand.insert(0, " ".join(commandGetArgv(command))) 72 | timeCommand.insert(0, "/usr/bin/time") 73 | timeCommand.insert(1, "-vo") 74 | timeCommand.insert(2, temppath) 75 | timeCommand.insert(3, "/bin/bash") 76 | timeCommand.insert(4, "-c") 77 | sys.stdout.write("running command: %s\n" % (" ".join(timeCommand))) 78 | filestdin = open(commandGetStdin(command), "r") 79 | filestdout = open("/dev/null", "w") 80 | exitcode = subprocess.call(timeCommand, stdin=filestdin, stdout=filestdout) 81 | filestdout.close() 82 | filestdin.close() 83 | printfile(temppath, sys.stdout) 84 | os.remove(temppath) 85 | sys.stdout.write("command status: %d\n" % (exitcode)) 86 | 87 | if len(sys.argv) < 4: 88 | sys.stdout.write("usage:\n") 89 | sys.stdout.write(" measuremem.py specdir instancename benchmark...\n") 90 | 91 | specdir=sys.argv[1] 92 | instancename=sys.argv[2] 93 | for benchmark in sys.argv[3:]: 94 | processbenchmark(specdir, instancename, benchmark) 95 | -------------------------------------------------------------------------------- /gperftools-metalloc/.gitignore: -------------------------------------------------------------------------------- 1 | *.[oa] 2 | *.la 3 | *.lo 4 | *~ 5 | /*.log 6 | /*.trs 7 | /.deps 8 | /.libs 9 | /GPATH 10 | /GRTAGS 11 | /GSYMS 12 | /GTAGS 13 | /ID 14 | /INSTALL 15 | /Makefile 16 | /Makefile.in 17 | /aclocal.m4 18 | /addressmap_unittest 19 | /addressmap_unittest.exe 20 | /atomicops_unittest 21 | /atomicops_unittest.exe 22 | /autom4te.cache/ 23 | /benchmark/.deps 24 | /benchmark/.dirstamp 25 | /compile 26 | /config.guess 27 | /config.log 28 | /config.status 29 | /config.sub 30 | /configure 31 | /current_allocated_bytes_test 32 | /current_allocated_bytes_test.exe 33 | /debugallocation_test 34 | /debugallocation_test.sh 35 | /depcomp 36 | /frag_unittest 37 | /frag_unittest.exe 38 | /getpc_test 39 | /gperftools-*.tar.gz 40 | /gperftools-*.zip 41 | /heap-checker-death_unittest.sh 42 | /heap-checker_debug_unittest 43 | /heap-checker_debug_unittest.sh 44 | /heap-checker_unittest 45 | /heap-checker_unittest.sh 46 | /heap-profiler_debug_unittest 47 | /heap-profiler_debug_unittest.sh 48 | /heap-profiler_unittest 49 | /heap-profiler_unittest.sh 50 | /install-sh 51 | /libprofiler.pc 52 | /libtcmalloc.pc 53 | /libtcmalloc_debug.pc 54 | /libtcmalloc_minimal.pc 55 | /libtcmalloc_minimal_debug.pc 56 | /libtool 57 | /low_level_alloc_unittest 58 | /low_level_alloc_unittest.exe 59 | /ltmain.sh 60 | /m4/libtool.m4 61 | /m4/ltoptions.m4 62 | /m4/ltsugar.m4 63 | /m4/ltversion.m4 64 | /m4/lt~obsolete.m4 65 | /malloc_bench 66 | /malloc_bench.exe 67 | /malloc_bench_shared 68 | /malloc_bench_shared.exe 69 | /malloc_extension_c_test 70 | /malloc_extension_debug_test 71 | /malloc_extension_test 72 | /malloc_extension_test.exe 73 | /malloc_hook_test 74 | /malloc_hook_test.exe 75 | /markidle_unittest 76 | /markidle_unittest.exe 77 | /maybe_threads_unittest.sh 78 | /memalign_debug_unittest 79 | /memalign_unittest 80 | /missing 81 | /packed_cache_test 82 | /packed_cache_test.exe 83 | /page_heap_test 84 | /page_heap_test.exe 85 | /pagemap_unittest 86 | /pagemap_unittest.exe 87 | /profile_handler_unittest 88 | /profiledata_unittest 89 | /profiler1_unittest 90 | /profiler2_unittest 91 | /profiler3_unittest 92 | /profiler4_unittest 93 | /profiler_unittest.sh 94 | /raw_printer_test 95 | /realloc_debug_unittest 96 | /realloc_unittest 97 | /realloc_unittest.exe 98 | /sampler_debug_test 99 | /sampler_test 100 | /sampling_debug_test 101 | /sampling_debug_test.sh 102 | /sampling_test 103 | /sampling_test.sh 104 | /simple_compat_test 105 | /src/.deps 106 | /src/.dirstamp 107 | /src/base/.deps 108 | /src/base/.dirstamp 109 | /src/config.h 110 | /src/config.h.in 111 | /src/gperftools/tcmalloc.h 112 | /src/stamp-h1 113 | /src/stamp-h1 114 | /src/tests/.deps 115 | /src/tests/.dirstamp 116 | /src/windows/.deps 117 | /src/windows/.dirstamp 118 | /stack_trace_table_test 119 | /stack_trace_table_test.exe 120 | /stacktrace_unittest 121 | /system_alloc_unittest 122 | /tcmalloc_and_profiler_unittest 123 | /tcmalloc_both_unittest 124 | /tcmalloc_debug_unittest 125 | /tcmalloc_large_heap_fragmentation_unittest 126 | /tcmalloc_large_unittest 127 | /tcmalloc_minimal_debug_unittest 128 | /tcmalloc_minimal_large_heap_fragmentation_unittest 129 | /tcmalloc_minimal_large_heap_fragmentation_unittest.exe 130 | /tcmalloc_minimal_large_unittest 131 | /tcmalloc_minimal_large_unittest.exe 132 | /tcmalloc_minimal_unittest 133 | /tcmalloc_minimal_unittest.exe 134 | /tcmalloc_unittest 135 | /tcmalloc_unittest.sh 136 | /test-driver 137 | /thread_dealloc_unittest 138 | /thread_dealloc_unittest.exe 139 | -------------------------------------------------------------------------------- /gperftools-metalloc/AUTHORS: -------------------------------------------------------------------------------- 1 | google-perftools@googlegroups.com 2 | 3 | -------------------------------------------------------------------------------- /gperftools-metalloc/COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 2005, Google Inc. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above 11 | copyright notice, this list of conditions and the following disclaimer 12 | in the documentation and/or other materials provided with the 13 | distribution. 14 | * Neither the name of Google Inc. nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /gperftools-metalloc/TODO: -------------------------------------------------------------------------------- 1 | HEAP PROFILER 2 | 3 | 1) Fix heap profiling under all STLs 4 | * Find out how to force non-glibc STL libraries to call new() and 5 | delete() for every allocation / deallocation. 6 | * Make heap profiler ignore STL-internal allocations for those 7 | libraries under which we cannot profile accurately, so we only 8 | see object-level leaks. 9 | 2) Remove dependency on tcmalloc? 10 | 3) Port to non-linux O/Ses (right now code uses /proc for library info) 11 | 4) Port to non-x86 architectures (locking code in spinlock is x86-specific) 12 | 5) Port to C? 13 | 6) Figure out how to get setenv() to work properly before main() in 14 | shared libaries, and get rid of the profile-naming hack once we 15 | do. (See HeapProfiler::Init().) 16 | 17 | 18 | HEAP CHECKER 19 | 20 | 1) Remove requirement that the heap-checker must be linked last into 21 | an application (hard! -- it needs its global constructor to run 22 | first) 23 | 24 | TCMALLOC 25 | 26 | 1) Implement mallinfo/mallopt 27 | 2) Have tcmalloc work correctly when libpthread is not linked in 28 | (currently working for glibc, could use other libc's too) 29 | 3) Return memory to the system when requirements drop 30 | 4) Explore coloring allocated objects to avoid cache conflicts 31 | 5) Explore biasing reclamation to larger addresses 32 | 6) Add contention stats to a synchronization.cc (can do spinlocks, 33 | but threads? -- may have to provide our own thread implementation) 34 | 35 | CPU PROFILER 36 | 37 | 1) Figure out how to get setenv() to work properly before main() in 38 | shared libaries(), and get rid of the profile-naming hack once we 39 | do. (See Profiler::GetUniquePathFromEnv().) 40 | 2) Resolve crashing problems on x86_64 (see README) 41 | 42 | STACKTRACE 43 | 44 | 1) Remove dependency on linux/x86 45 | 46 | --- 47 | 11 March 2008 48 | -------------------------------------------------------------------------------- /gperftools-metalloc/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | autoreconf -i 4 | -------------------------------------------------------------------------------- /gperftools-metalloc/benchmark/run_benchmark.h: -------------------------------------------------------------------------------- 1 | // -*- Mode: C; c-basic-offset: 2; indent-tabs-mode: nil -*- 2 | // Redistribution and use in source and binary forms, with or without 3 | // modification, are permitted provided that the following conditions are 4 | // met: 5 | // 6 | // * Redistributions of source code must retain the above copyright 7 | // notice, this list of conditions and the following disclaimer. 8 | // * Redistributions in binary form must reproduce the above 9 | // copyright notice, this list of conditions and the following disclaimer 10 | // in the documentation and/or other materials provided with the 11 | // distribution. 12 | // * Neither the name of Google Inc. nor the names of its 13 | // contributors may be used to endorse or promote products derived from 14 | // this software without specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | #ifndef _RUN_BENCHMARK_H_ 28 | #define _RUN_BENCHMARK_H_ 29 | #include 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | typedef void (*bench_body)(long iterations, uintptr_t param); 36 | 37 | void report_benchmark(const char *name, bench_body body, uintptr_t param); 38 | 39 | #ifdef __cplusplus 40 | } // extern "C" 41 | #endif 42 | 43 | #endif // _RUN_BENCHMARK_H_ 44 | -------------------------------------------------------------------------------- /gperftools-metalloc/doc/designstyle.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: #ffffff; 3 | color: black; 4 | margin-right: 1in; 5 | margin-left: 1in; 6 | } 7 | 8 | 9 | h1, h2, h3, h4, h5, h6 { 10 | color: #3366ff; 11 | font-family: sans-serif; 12 | } 13 | @media print { 14 | /* Darker version for printing */ 15 | h1, h2, h3, h4, h5, h6 { 16 | color: #000080; 17 | font-family: helvetica, sans-serif; 18 | } 19 | } 20 | 21 | h1 { 22 | text-align: center; 23 | font-size: 18pt; 24 | } 25 | h2 { 26 | margin-left: -0.5in; 27 | } 28 | h3 { 29 | margin-left: -0.25in; 30 | } 31 | h4 { 32 | margin-left: -0.125in; 33 | } 34 | hr { 35 | margin-left: -1in; 36 | } 37 | 38 | /* Definition lists: definition term bold */ 39 | dt { 40 | font-weight: bold; 41 | } 42 | 43 | address { 44 | text-align: right; 45 | } 46 | /* Use the tag for bits of code and for variables and objects. */ 47 | code,pre,samp,var { 48 | color: #006000; 49 | } 50 | /* Use the tag for file and directory paths and names. */ 51 | file { 52 | color: #905050; 53 | font-family: monospace; 54 | } 55 | /* Use the tag for stuff the user should type. */ 56 | kbd { 57 | color: #600000; 58 | } 59 | div.note p { 60 | float: right; 61 | width: 3in; 62 | margin-right: 0%; 63 | padding: 1px; 64 | border: 2px solid #6060a0; 65 | background-color: #fffff0; 66 | } 67 | 68 | UL.nobullets { 69 | list-style-type: none; 70 | list-style-image: none; 71 | margin-left: -1em; 72 | } 73 | 74 | /* pretty printing styles. See prettify.js */ 75 | .str { color: #080; } 76 | .kwd { color: #008; } 77 | .com { color: #800; } 78 | .typ { color: #606; } 79 | .lit { color: #066; } 80 | .pun { color: #660; } 81 | .pln { color: #000; } 82 | .tag { color: #008; } 83 | .atn { color: #606; } 84 | .atv { color: #080; } 85 | pre.prettyprint { padding: 2px; border: 1px solid #888; } 86 | 87 | .embsrc { background: #eee; } 88 | 89 | @media print { 90 | .str { color: #060; } 91 | .kwd { color: #006; font-weight: bold; } 92 | .com { color: #600; font-style: italic; } 93 | .typ { color: #404; font-weight: bold; } 94 | .lit { color: #044; } 95 | .pun { color: #440; } 96 | .pln { color: #000; } 97 | .tag { color: #006; font-weight: bold; } 98 | .atn { color: #404; } 99 | .atv { color: #060; } 100 | } 101 | 102 | /* Table Column Headers */ 103 | .hdr { 104 | color: #006; 105 | font-weight: bold; 106 | background-color: #dddddd; } 107 | .hdr2 { 108 | color: #006; 109 | background-color: #eeeeee; } -------------------------------------------------------------------------------- /gperftools-metalloc/doc/heap-example1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vusec/dangsan/72b3d813683359f8f3d3a168bca9d7c691340cef/gperftools-metalloc/doc/heap-example1.png -------------------------------------------------------------------------------- /gperftools-metalloc/doc/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Gperftools 5 | 6 | 7 | 8 | 14 | 15 |
16 | Last modified: Thu Feb 2 14:40:47 PST 2012 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /gperftools-metalloc/doc/overview.dot: -------------------------------------------------------------------------------- 1 | digraph Overview { 2 | node [shape = box] 3 | 4 | {rank=same 5 | T1 [label="Thread Cache"] 6 | Tsep [label="...", shape=plaintext] 7 | Tn [label="Thread Cache"] 8 | T1 -> Tsep -> Tn [style=invis] 9 | } 10 | 11 | C [label="Central\nHeap"] 12 | T1 -> C [dir=both] 13 | Tn -> C [dir=both] 14 | 15 | } 16 | -------------------------------------------------------------------------------- /gperftools-metalloc/doc/overview.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vusec/dangsan/72b3d813683359f8f3d3a168bca9d7c691340cef/gperftools-metalloc/doc/overview.gif -------------------------------------------------------------------------------- /gperftools-metalloc/doc/pageheap.dot: -------------------------------------------------------------------------------- 1 | digraph PageHeap { 2 | rankdir=LR 3 | node [shape=box, width=0.3, height=0.3] 4 | nodesep=.05 5 | 6 | heap [shape=record, height=3, label="1 page|2 pages|3 pages|...|255 pages|rest"] 7 | O0 [shape=record, label=""] 8 | O1 [shape=record, label=""] 9 | O2 [shape=record, label="{|}"] 10 | O3 [shape=record, label="{|}"] 11 | O4 [shape=record, label="{||}"] 12 | O5 [shape=record, label="{||}"] 13 | O6 [shape=record, label="{|...|}"] 14 | O7 [shape=record, label="{|...|}"] 15 | O8 [shape=record, label="{|.....|}"] 16 | O9 [shape=record, label="{|.....|}"] 17 | sep1 [shape=plaintext, label="..."] 18 | sep2 [shape=plaintext, label="..."] 19 | sep3 [shape=plaintext, label="..."] 20 | sep4 [shape=plaintext, label="..."] 21 | sep5 [shape=plaintext, label="..."] 22 | 23 | heap:f0 -> O0 -> O1 -> sep1 24 | heap:f1 -> O2 -> O3 -> sep2 25 | heap:f2 -> O4 -> O5 -> sep3 26 | heap:f255 -> O6 -> O7 -> sep4 27 | heap:frest -> O8 -> O9 -> sep5 28 | 29 | } 30 | -------------------------------------------------------------------------------- /gperftools-metalloc/doc/pageheap.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vusec/dangsan/72b3d813683359f8f3d3a168bca9d7c691340cef/gperftools-metalloc/doc/pageheap.gif -------------------------------------------------------------------------------- /gperftools-metalloc/doc/pprof-test-big.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vusec/dangsan/72b3d813683359f8f3d3a168bca9d7c691340cef/gperftools-metalloc/doc/pprof-test-big.gif -------------------------------------------------------------------------------- /gperftools-metalloc/doc/pprof-test.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vusec/dangsan/72b3d813683359f8f3d3a168bca9d7c691340cef/gperftools-metalloc/doc/pprof-test.gif -------------------------------------------------------------------------------- /gperftools-metalloc/doc/pprof-vsnprintf-big.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vusec/dangsan/72b3d813683359f8f3d3a168bca9d7c691340cef/gperftools-metalloc/doc/pprof-vsnprintf-big.gif -------------------------------------------------------------------------------- /gperftools-metalloc/doc/pprof-vsnprintf.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vusec/dangsan/72b3d813683359f8f3d3a168bca9d7c691340cef/gperftools-metalloc/doc/pprof-vsnprintf.gif -------------------------------------------------------------------------------- /gperftools-metalloc/doc/pprof.1: -------------------------------------------------------------------------------- 1 | .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.23. 2 | .TH PPROF "1" "February 2005" "pprof (part of gperftools)" Google 3 | .SH NAME 4 | pprof \- manual page for pprof (part of gperftools) 5 | .SH SYNOPSIS 6 | .B pprof 7 | [\fIoptions\fR] \fI \fR 8 | .SH DESCRIPTION 9 | .IP 10 | Prints specified cpu- or heap-profile 11 | .SH OPTIONS 12 | .TP 13 | \fB\-\-cum\fR 14 | Sort by cumulative data 15 | .TP 16 | \fB\-\-base=\fR 17 | Subtract from before display 18 | .SS "Reporting Granularity:" 19 | .TP 20 | \fB\-\-addresses\fR 21 | Report at address level 22 | .TP 23 | \fB\-\-lines\fR 24 | Report at source line level 25 | .TP 26 | \fB\-\-functions\fR 27 | Report at function level [default] 28 | .TP 29 | \fB\-\-files\fR 30 | Report at source file level 31 | .SS "Output type:" 32 | .TP 33 | \fB\-\-text\fR 34 | Generate text report [default] 35 | .TP 36 | \fB\-\-gv\fR 37 | Generate Postscript and display 38 | .TP 39 | \fB\-\-list=\fR 40 | Generate source listing of matching routines 41 | .TP 42 | \fB\-\-disasm=\fR 43 | Generate disassembly of matching routines 44 | .TP 45 | \fB\-\-dot\fR 46 | Generate DOT file to stdout 47 | .TP 48 | \fB\-\-ps\fR 49 | Generate Postcript to stdout 50 | .TP 51 | \fB\-\-pdf\fR 52 | Generate PDF to stdout 53 | .TP 54 | \fB\-\-gif\fR 55 | Generate GIF to stdout 56 | .SS "Heap-Profile Options:" 57 | .TP 58 | \fB\-\-inuse_space\fR 59 | Display in-use (mega)bytes [default] 60 | .TP 61 | \fB\-\-inuse_objects\fR 62 | Display in-use objects 63 | .TP 64 | \fB\-\-alloc_space\fR 65 | Display allocated (mega)bytes 66 | .TP 67 | \fB\-\-alloc_objects\fR 68 | Display allocated objects 69 | .TP 70 | \fB\-\-show_bytes\fR 71 | Display space in bytes 72 | .TP 73 | \fB\-\-drop_negative\fR 74 | Ignore negaive differences 75 | .SS "Call-graph Options:" 76 | .TP 77 | \fB\-\-nodecount=\fR 78 | Show at most so many nodes [default=80] 79 | .TP 80 | \fB\-\-nodefraction=\fR 81 | Hide nodes below *total [default=.005] 82 | .TP 83 | \fB\-\-edgefraction=\fR 84 | Hide edges below *total [default=.001] 85 | .TP 86 | \fB\-\-focus=\fR 87 | Focus on nodes matching 88 | .TP 89 | \fB\-\-ignore=\fR 90 | Ignore nodes matching 91 | .TP 92 | \fB\-\-scale=\fR 93 | Set GV scaling [default=0] 94 | .SH EXAMPLES 95 | 96 | pprof /bin/ls ls.prof 97 | .IP 98 | Outputs one line per procedure 99 | .PP 100 | pprof \fB\-\-gv\fR /bin/ls ls.prof 101 | .IP 102 | Displays annotated call-graph via 'gv' 103 | .PP 104 | pprof \fB\-\-gv\fR \fB\-\-focus\fR=\fIMutex\fR /bin/ls ls.prof 105 | .IP 106 | Restricts to code paths including a .*Mutex.* entry 107 | .PP 108 | pprof \fB\-\-gv\fR \fB\-\-focus\fR=\fIMutex\fR \fB\-\-ignore\fR=\fIstring\fR /bin/ls ls.prof 109 | .IP 110 | Code paths including Mutex but not string 111 | .PP 112 | pprof \fB\-\-list\fR=\fIgetdir\fR /bin/ls ls.prof 113 | .IP 114 | Dissassembly (with per-line annotations) for getdir() 115 | .PP 116 | pprof \fB\-\-disasm\fR=\fIgetdir\fR /bin/ls ls.prof 117 | .IP 118 | Dissassembly (with per-PC annotations) for getdir() 119 | .SH COPYRIGHT 120 | Copyright \(co 2005 Google Inc. 121 | .SH "SEE ALSO" 122 | Further documentation for 123 | .B pprof 124 | is maintained as a web page called 125 | .B cpu_profiler.html 126 | and is likely installed at one of the following locations: 127 | .IP 128 | .B /usr/share/gperftools/cpu_profiler.html 129 | .br 130 | .B /usr/local/share/gperftools/cpu_profiler.html 131 | .PP 132 | -------------------------------------------------------------------------------- /gperftools-metalloc/doc/pprof.see_also: -------------------------------------------------------------------------------- 1 | [see also] 2 | Further documentation for 3 | .B pprof 4 | is maintained as a web page called 5 | .B cpu_profiler.html 6 | and is likely installed at one of the following locations: 7 | .IP 8 | .B /usr/share/gperftools/cpu_profiler.html 9 | .br 10 | .B /usr/local/share/gperftools/cpu_profiler.html 11 | .PP 12 | -------------------------------------------------------------------------------- /gperftools-metalloc/doc/spanmap.dot: -------------------------------------------------------------------------------- 1 | digraph SpanMap { 2 | node [shape=box, width=0.3, height=0.3] 3 | nodesep=.05 4 | 5 | map [shape=record, width=6, label="||||||||||"] 6 | S0 [label="a"] 7 | S1 [label="b"] 8 | S2 [label="c"] 9 | S3 [label="d"] 10 | map:f0 -> S0 11 | map:f1 -> S0 12 | map:f2 -> S1 13 | map:f3 -> S2 14 | map:f4 -> S2 15 | map:f5 -> S2 16 | map:f6 -> S2 17 | map:f7 -> S2 18 | map:f8 -> S3 19 | map:f9 -> S3 20 | map:f10 -> S3 21 | 22 | } 23 | -------------------------------------------------------------------------------- /gperftools-metalloc/doc/spanmap.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vusec/dangsan/72b3d813683359f8f3d3a168bca9d7c691340cef/gperftools-metalloc/doc/spanmap.gif -------------------------------------------------------------------------------- /gperftools-metalloc/doc/tcmalloc-opspercpusec.vs.threads.1024.bytes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vusec/dangsan/72b3d813683359f8f3d3a168bca9d7c691340cef/gperftools-metalloc/doc/tcmalloc-opspercpusec.vs.threads.1024.bytes.png -------------------------------------------------------------------------------- /gperftools-metalloc/doc/tcmalloc-opspercpusec.vs.threads.128.bytes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vusec/dangsan/72b3d813683359f8f3d3a168bca9d7c691340cef/gperftools-metalloc/doc/tcmalloc-opspercpusec.vs.threads.128.bytes.png -------------------------------------------------------------------------------- /gperftools-metalloc/doc/tcmalloc-opspercpusec.vs.threads.131072.bytes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vusec/dangsan/72b3d813683359f8f3d3a168bca9d7c691340cef/gperftools-metalloc/doc/tcmalloc-opspercpusec.vs.threads.131072.bytes.png -------------------------------------------------------------------------------- /gperftools-metalloc/doc/tcmalloc-opspercpusec.vs.threads.16384.bytes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vusec/dangsan/72b3d813683359f8f3d3a168bca9d7c691340cef/gperftools-metalloc/doc/tcmalloc-opspercpusec.vs.threads.16384.bytes.png -------------------------------------------------------------------------------- /gperftools-metalloc/doc/tcmalloc-opspercpusec.vs.threads.2048.bytes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vusec/dangsan/72b3d813683359f8f3d3a168bca9d7c691340cef/gperftools-metalloc/doc/tcmalloc-opspercpusec.vs.threads.2048.bytes.png -------------------------------------------------------------------------------- /gperftools-metalloc/doc/tcmalloc-opspercpusec.vs.threads.256.bytes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vusec/dangsan/72b3d813683359f8f3d3a168bca9d7c691340cef/gperftools-metalloc/doc/tcmalloc-opspercpusec.vs.threads.256.bytes.png -------------------------------------------------------------------------------- /gperftools-metalloc/doc/tcmalloc-opspercpusec.vs.threads.32768.bytes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vusec/dangsan/72b3d813683359f8f3d3a168bca9d7c691340cef/gperftools-metalloc/doc/tcmalloc-opspercpusec.vs.threads.32768.bytes.png -------------------------------------------------------------------------------- /gperftools-metalloc/doc/tcmalloc-opspercpusec.vs.threads.4096.bytes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vusec/dangsan/72b3d813683359f8f3d3a168bca9d7c691340cef/gperftools-metalloc/doc/tcmalloc-opspercpusec.vs.threads.4096.bytes.png -------------------------------------------------------------------------------- /gperftools-metalloc/doc/tcmalloc-opspercpusec.vs.threads.512.bytes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vusec/dangsan/72b3d813683359f8f3d3a168bca9d7c691340cef/gperftools-metalloc/doc/tcmalloc-opspercpusec.vs.threads.512.bytes.png -------------------------------------------------------------------------------- /gperftools-metalloc/doc/tcmalloc-opspercpusec.vs.threads.64.bytes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vusec/dangsan/72b3d813683359f8f3d3a168bca9d7c691340cef/gperftools-metalloc/doc/tcmalloc-opspercpusec.vs.threads.64.bytes.png -------------------------------------------------------------------------------- /gperftools-metalloc/doc/tcmalloc-opspercpusec.vs.threads.65536.bytes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vusec/dangsan/72b3d813683359f8f3d3a168bca9d7c691340cef/gperftools-metalloc/doc/tcmalloc-opspercpusec.vs.threads.65536.bytes.png -------------------------------------------------------------------------------- /gperftools-metalloc/doc/tcmalloc-opspercpusec.vs.threads.8192.bytes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vusec/dangsan/72b3d813683359f8f3d3a168bca9d7c691340cef/gperftools-metalloc/doc/tcmalloc-opspercpusec.vs.threads.8192.bytes.png -------------------------------------------------------------------------------- /gperftools-metalloc/doc/tcmalloc-opspersec.vs.size.1.threads.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vusec/dangsan/72b3d813683359f8f3d3a168bca9d7c691340cef/gperftools-metalloc/doc/tcmalloc-opspersec.vs.size.1.threads.png -------------------------------------------------------------------------------- /gperftools-metalloc/doc/tcmalloc-opspersec.vs.size.12.threads.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vusec/dangsan/72b3d813683359f8f3d3a168bca9d7c691340cef/gperftools-metalloc/doc/tcmalloc-opspersec.vs.size.12.threads.png -------------------------------------------------------------------------------- /gperftools-metalloc/doc/tcmalloc-opspersec.vs.size.16.threads.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vusec/dangsan/72b3d813683359f8f3d3a168bca9d7c691340cef/gperftools-metalloc/doc/tcmalloc-opspersec.vs.size.16.threads.png -------------------------------------------------------------------------------- /gperftools-metalloc/doc/tcmalloc-opspersec.vs.size.2.threads.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vusec/dangsan/72b3d813683359f8f3d3a168bca9d7c691340cef/gperftools-metalloc/doc/tcmalloc-opspersec.vs.size.2.threads.png -------------------------------------------------------------------------------- /gperftools-metalloc/doc/tcmalloc-opspersec.vs.size.20.threads.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vusec/dangsan/72b3d813683359f8f3d3a168bca9d7c691340cef/gperftools-metalloc/doc/tcmalloc-opspersec.vs.size.20.threads.png -------------------------------------------------------------------------------- /gperftools-metalloc/doc/tcmalloc-opspersec.vs.size.3.threads.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vusec/dangsan/72b3d813683359f8f3d3a168bca9d7c691340cef/gperftools-metalloc/doc/tcmalloc-opspersec.vs.size.3.threads.png -------------------------------------------------------------------------------- /gperftools-metalloc/doc/tcmalloc-opspersec.vs.size.4.threads.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vusec/dangsan/72b3d813683359f8f3d3a168bca9d7c691340cef/gperftools-metalloc/doc/tcmalloc-opspersec.vs.size.4.threads.png -------------------------------------------------------------------------------- /gperftools-metalloc/doc/tcmalloc-opspersec.vs.size.5.threads.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vusec/dangsan/72b3d813683359f8f3d3a168bca9d7c691340cef/gperftools-metalloc/doc/tcmalloc-opspersec.vs.size.5.threads.png -------------------------------------------------------------------------------- /gperftools-metalloc/doc/tcmalloc-opspersec.vs.size.8.threads.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vusec/dangsan/72b3d813683359f8f3d3a168bca9d7c691340cef/gperftools-metalloc/doc/tcmalloc-opspersec.vs.size.8.threads.png -------------------------------------------------------------------------------- /gperftools-metalloc/doc/threadheap.dot: -------------------------------------------------------------------------------- 1 | digraph ThreadHeap { 2 | rankdir=LR 3 | node [shape=box, width=0.3, height=0.3] 4 | nodesep=.05 5 | 6 | heap [shape=record, height=2, label="class 0|class 1|class 2|..."] 7 | O0 [label=""] 8 | O1 [label=""] 9 | O2 [label=""] 10 | O3 [label=""] 11 | O4 [label=""] 12 | O5 [label=""] 13 | sep1 [shape=plaintext, label="..."] 14 | sep2 [shape=plaintext, label="..."] 15 | sep3 [shape=plaintext, label="..."] 16 | 17 | heap:f0 -> O0 -> O1 -> sep1 18 | heap:f1 -> O2 -> O3 -> sep2 19 | heap:f2 -> O4 -> O5 -> sep3 20 | 21 | } 22 | -------------------------------------------------------------------------------- /gperftools-metalloc/doc/threadheap.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vusec/dangsan/72b3d813683359f8f3d3a168bca9d7c691340cef/gperftools-metalloc/doc/threadheap.gif -------------------------------------------------------------------------------- /gperftools-metalloc/m4/ac_have_attribute.m4: -------------------------------------------------------------------------------- 1 | AC_DEFUN([AX_C___ATTRIBUTE__], [ 2 | AC_MSG_CHECKING(for __attribute__) 3 | AC_CACHE_VAL(ac_cv___attribute__, [ 4 | AC_TRY_COMPILE( 5 | [#include 6 | static void foo(void) __attribute__ ((unused)); 7 | void foo(void) { exit(1); }], 8 | [], 9 | ac_cv___attribute__=yes, 10 | ac_cv___attribute__=no 11 | )]) 12 | if test "$ac_cv___attribute__" = "yes"; then 13 | AC_DEFINE(HAVE___ATTRIBUTE__, 1, [define if your compiler has __attribute__]) 14 | fi 15 | AC_MSG_RESULT($ac_cv___attribute__) 16 | ]) 17 | -------------------------------------------------------------------------------- /gperftools-metalloc/m4/acx_nanosleep.m4: -------------------------------------------------------------------------------- 1 | # Check for support for nanosleep. It's defined in , but on 2 | # some systems, such as solaris, you need to link in a library to use it. 3 | # We set acx_nanosleep_ok if nanosleep is supported; in that case, 4 | # NANOSLEEP_LIBS is set to whatever libraries are needed to support 5 | # nanosleep. 6 | 7 | AC_DEFUN([ACX_NANOSLEEP], 8 | [AC_MSG_CHECKING(if nanosleep requires any libraries) 9 | AC_LANG_SAVE 10 | AC_LANG_C 11 | acx_nanosleep_ok="no" 12 | NANOSLEEP_LIBS= 13 | # For most folks, this should just work 14 | AC_TRY_LINK([#include ], 15 | [static struct timespec ts; nanosleep(&ts, NULL);], 16 | [acx_nanosleep_ok=yes]) 17 | # For solaris, we may need -lrt 18 | if test "x$acx_nanosleep_ok" != "xyes"; then 19 | OLD_LIBS="$LIBS" 20 | LIBS="-lrt $LIBS" 21 | AC_TRY_LINK([#include ], 22 | [static struct timespec ts; nanosleep(&ts, NULL);], 23 | [acx_nanosleep_ok=yes]) 24 | if test "x$acx_nanosleep_ok" = "xyes"; then 25 | NANOSLEEP_LIBS="-lrt" 26 | fi 27 | LIBS="$OLD_LIBS" 28 | fi 29 | if test "x$acx_nanosleep_ok" != "xyes"; then 30 | AC_MSG_ERROR([cannot find the nanosleep function]) 31 | else 32 | AC_MSG_RESULT(${NANOSLEEP_LIBS:-no}) 33 | fi 34 | AC_LANG_RESTORE 35 | ]) 36 | -------------------------------------------------------------------------------- /gperftools-metalloc/m4/compiler_characteristics.m4: -------------------------------------------------------------------------------- 1 | # Check compiler characteristics (e.g. type sizes, PRIxx macros, ...) 2 | 3 | # If types $1 and $2 are compatible, perform action $3 4 | AC_DEFUN([AC_TYPES_COMPATIBLE], 5 | [AC_TRY_COMPILE([#include ], [$1 v1 = 0; $2 v2 = 0; return (&v1 - &v2)], $3)]) 6 | 7 | define(AC_PRIUS_COMMENT, [printf format code for printing a size_t and ssize_t]) 8 | 9 | AC_DEFUN([AC_COMPILER_CHARACTERISTICS], 10 | [AC_CACHE_CHECK(AC_PRIUS_COMMENT, ac_cv_formatting_prius_prefix, 11 | [AC_TYPES_COMPATIBLE(unsigned int, size_t, 12 | ac_cv_formatting_prius_prefix=; ac_cv_prius_defined=1) 13 | AC_TYPES_COMPATIBLE(unsigned long, size_t, 14 | ac_cv_formatting_prius_prefix=l; ac_cv_prius_defined=1) 15 | AC_TYPES_COMPATIBLE(unsigned long long, size_t, 16 | ac_cv_formatting_prius_prefix=ll; ac_cv_prius_defined=1 17 | )]) 18 | if test -z "$ac_cv_prius_defined"; then 19 | ac_cv_formatting_prius_prefix=z; 20 | fi 21 | AC_DEFINE_UNQUOTED(PRIuS, "${ac_cv_formatting_prius_prefix}u", AC_PRIUS_COMMENT) 22 | AC_DEFINE_UNQUOTED(PRIxS, "${ac_cv_formatting_prius_prefix}x", AC_PRIUS_COMMENT) 23 | AC_DEFINE_UNQUOTED(PRIdS, "${ac_cv_formatting_prius_prefix}d", AC_PRIUS_COMMENT) 24 | ]) 25 | -------------------------------------------------------------------------------- /gperftools-metalloc/m4/install_prefix.m4: -------------------------------------------------------------------------------- 1 | AC_DEFUN([AC_INSTALL_PREFIX], 2 | [ac_cv_install_prefix="$prefix"; 3 | if test x"$ac_cv_install_prefix" = x"NONE" ; then 4 | ac_cv_install_prefix="$ac_default_prefix"; 5 | fi 6 | AC_DEFINE_UNQUOTED(INSTALL_PREFIX, "$ac_cv_install_prefix", 7 | [prefix where we look for installed files]) 8 | ]) 9 | -------------------------------------------------------------------------------- /gperftools-metalloc/m4/namespaces.m4: -------------------------------------------------------------------------------- 1 | # Checks whether the compiler implements namespaces 2 | AC_DEFUN([AC_CXX_NAMESPACES], 3 | [AC_CACHE_CHECK(whether the compiler implements namespaces, 4 | ac_cv_cxx_namespaces, 5 | [AC_LANG_SAVE 6 | AC_LANG_CPLUSPLUS 7 | AC_TRY_COMPILE([namespace Outer { 8 | namespace Inner { int i = 0; }}], 9 | [using namespace Outer::Inner; return i;], 10 | ac_cv_cxx_namespaces=yes, 11 | ac_cv_cxx_namespaces=no) 12 | AC_LANG_RESTORE]) 13 | if test "$ac_cv_cxx_namespaces" = yes; then 14 | AC_DEFINE(HAVE_NAMESPACES, 1, [define if the compiler implements namespaces]) 15 | fi]) 16 | -------------------------------------------------------------------------------- /gperftools-metalloc/m4/program_invocation_name.m4: -------------------------------------------------------------------------------- 1 | # We need to be careful to avoid having the reference to 2 | # program_invocation_name optimized out. We do that by 3 | # returning the value. 4 | 5 | AC_DEFUN([AC_PROGRAM_INVOCATION_NAME], 6 | [AC_CACHE_CHECK( 7 | for program_invocation_name, 8 | ac_cv_have_program_invocation_name, 9 | AC_TRY_LINK([extern char* program_invocation_name;], 10 | [return *program_invocation_name;], 11 | [ac_cv_have_program_invocation_name=yes], 12 | [ac_cv_have_program_invocation_name=no]) 13 | ) 14 | if test "$ac_cv_have_program_invocation_name" = "yes"; then 15 | AC_DEFINE(HAVE_PROGRAM_INVOCATION_NAME, 1, 16 | [define if libc has program_invocation_name]) 17 | fi 18 | ]) 19 | 20 | -------------------------------------------------------------------------------- /gperftools-metalloc/m4/stl_namespace.m4: -------------------------------------------------------------------------------- 1 | # We check what namespace stl code like vector expects to be executed in 2 | 3 | AC_DEFUN([AC_CXX_STL_NAMESPACE], 4 | [AC_CACHE_CHECK( 5 | what namespace STL code is in, 6 | ac_cv_cxx_stl_namespace, 7 | [AC_REQUIRE([AC_CXX_NAMESPACES]) 8 | AC_LANG_SAVE 9 | AC_LANG_CPLUSPLUS 10 | AC_TRY_COMPILE([#include ], 11 | [vector t; return 0;], 12 | ac_cv_cxx_stl_namespace=none) 13 | AC_TRY_COMPILE([#include ], 14 | [std::vector t; return 0;], 15 | ac_cv_cxx_stl_namespace=std) 16 | AC_LANG_RESTORE]) 17 | if test "$ac_cv_cxx_stl_namespace" = none; then 18 | AC_DEFINE(STL_NAMESPACE,, 19 | [the namespace where STL code like vector<> is defined]) 20 | fi 21 | if test "$ac_cv_cxx_stl_namespace" = std; then 22 | AC_DEFINE(STL_NAMESPACE,std, 23 | [the namespace where STL code like vector<> is defined]) 24 | fi 25 | ]) 26 | -------------------------------------------------------------------------------- /gperftools-metalloc/packages/deb.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | # This takes one commandline argument, the name of the package. If no 4 | # name is given, then we'll end up just using the name associated with 5 | # an arbitrary .tar.gz file in the rootdir. That's fine: there's probably 6 | # only one. 7 | # 8 | # Run this from the 'packages' directory, just under rootdir 9 | 10 | ## Set LIB to lib if exporting a library, empty-string else 11 | LIB= 12 | #LIB=lib 13 | 14 | PACKAGE="$1" 15 | VERSION="$2" 16 | 17 | # We can only build Debian packages, if the Debian build tools are installed 18 | if [ \! -x /usr/bin/debuild ]; then 19 | echo "Cannot find /usr/bin/debuild. Not building Debian packages." 1>&2 20 | exit 0 21 | fi 22 | 23 | # Double-check we're in the packages directory, just under rootdir 24 | if [ \! -r ../Makefile -a \! -r ../INSTALL ]; then 25 | echo "Must run $0 in the 'packages' directory, under the root directory." 1>&2 26 | echo "Also, you must run \"make dist\" before running this script." 1>&2 27 | exit 0 28 | fi 29 | 30 | # Find the top directory for this package 31 | topdir="${PWD%/*}" 32 | 33 | # Find the tar archive built by "make dist" 34 | archive="${PACKAGE}-${VERSION}" 35 | archive_with_underscore="${PACKAGE}_${VERSION}" 36 | if [ -z "${archive}" ]; then 37 | echo "Cannot find ../$PACKAGE*.tar.gz. Run \"make dist\" first." 1>&2 38 | exit 0 39 | fi 40 | 41 | # Create a pristine directory for building the Debian package files 42 | trap 'rm -rf '`pwd`/tmp'; exit $?' EXIT SIGHUP SIGINT SIGTERM 43 | 44 | rm -rf tmp 45 | mkdir -p tmp 46 | cd tmp 47 | 48 | # Debian has very specific requirements about the naming of build 49 | # directories, and tar archives. It also wants to write all generated 50 | # packages to the parent of the source directory. We accommodate these 51 | # requirements by building directly from the tar file. 52 | ln -s "${topdir}/${archive}.tar.gz" "${LIB}${archive}.orig.tar.gz" 53 | # Some version of debuilder want foo.orig.tar.gz with _ between versions. 54 | ln -s "${topdir}/${archive}.tar.gz" "${LIB}${archive_with_underscore}.orig.tar.gz" 55 | tar zfx "${LIB}${archive}.orig.tar.gz" 56 | [ -n "${LIB}" ] && mv "${archive}" "${LIB}${archive}" 57 | cd "${LIB}${archive}" 58 | # This is one of those 'specific requirements': where the deb control files live 59 | cp -a "packages/deb" "debian" 60 | 61 | # Now, we can call Debian's standard build tool 62 | debuild -uc -us 63 | cd ../.. # get back to the original top-level dir 64 | 65 | # We'll put the result in a subdirectory that's named after the OS version 66 | # we've made this .deb file for. 67 | destdir="debian-$(cat /etc/debian_version 2>/dev/null || echo UNKNOWN)" 68 | 69 | rm -rf "$destdir" 70 | mkdir -p "$destdir" 71 | mv $(find tmp -mindepth 1 -maxdepth 1 -type f) "$destdir" 72 | 73 | echo 74 | echo "The Debian package files are located in $PWD/$destdir" 75 | -------------------------------------------------------------------------------- /gperftools-metalloc/packages/deb/README: -------------------------------------------------------------------------------- 1 | The list of files here isn't complete. For a step-by-step guide on 2 | how to set this package up correctly, check out 3 | http://www.debian.org/doc/maint-guide/ 4 | 5 | Most of the files that are in this directory are boilerplate. 6 | However, you may need to change the list of binary-arch dependencies 7 | in 'rules'. 8 | -------------------------------------------------------------------------------- /gperftools-metalloc/packages/deb/compat: -------------------------------------------------------------------------------- 1 | 4 2 | -------------------------------------------------------------------------------- /gperftools-metalloc/packages/deb/control: -------------------------------------------------------------------------------- 1 | Source: gperftools 2 | Priority: optional 3 | Maintainer: gperftools Contributors 4 | Build-Depends: debhelper (>= 4.0.0), binutils 5 | Standards-Version: 3.6.1 6 | 7 | Package: libgperftools-dev 8 | Section: libdevel 9 | Architecture: any 10 | Depends: libgperftools0 (= ${Source-Version}) 11 | Description: libraries for CPU and heap analysis, plus an efficient thread-caching malloc 12 | The gperftools package contains some utilities to improve and 13 | analyze the performance of C++ programs. This includes an optimized 14 | thread-caching malloc() and cpu and heap profiling utilities. The 15 | devel package contains static and debug libraries and header files 16 | for developing applications that use the gperftools package. 17 | 18 | Package: libgperftools0 19 | Section: libs 20 | Architecture: any 21 | Depends: ${shlibs:Depends} 22 | Description: libraries for CPU and heap analysis, plus an efficient thread-caching malloc 23 | The gperftools package contains some utilities to improve and 24 | analyze the performance of C++ programs. This includes an optimized 25 | thread-caching malloc() and cpu and heap profiling utilities. 26 | -------------------------------------------------------------------------------- /gperftools-metalloc/packages/deb/copyright: -------------------------------------------------------------------------------- 1 | This package was debianized by gperftools Contributors 2 | on Sat, 20 Jul 2013 14:21:10 -0700. 3 | 4 | It was downloaded from http://code.google.com/p/gperftools/downloads/list 5 | 6 | Upstream Author: google-perftools@googlegroups.com 7 | 8 | Copyright (c) 2005, Google Inc. 9 | All rights reserved. 10 | 11 | Copyright (c) 2013, gperftools Contributors 12 | All rights reserved. 13 | 14 | Redistribution and use in source and binary forms, with or without 15 | modification, are permitted provided that the following conditions are 16 | met: 17 | 18 | * Redistributions of source code must retain the above copyright 19 | notice, this list of conditions and the following disclaimer. 20 | * Redistributions in binary form must reproduce the above 21 | copyright notice, this list of conditions and the following disclaimer 22 | in the documentation and/or other materials provided with the 23 | distribution. 24 | * Neither the name of Google Inc. nor the names of its 25 | contributors may be used to endorse or promote products derived from 26 | this software without specific prior written permission. 27 | 28 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 29 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 30 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 31 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 32 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 33 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 34 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 35 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 36 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 37 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 38 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 | -------------------------------------------------------------------------------- /gperftools-metalloc/packages/deb/docs: -------------------------------------------------------------------------------- 1 | AUTHORS 2 | COPYING 3 | ChangeLog 4 | INSTALL 5 | NEWS 6 | README 7 | TODO 8 | doc/cpuprofile.html 9 | doc/cpuprofile-fileformat.html 10 | doc/designstyle.css 11 | doc/heap-example1.png 12 | doc/heap_checker.html 13 | doc/heapprofile.html 14 | doc/index.html 15 | doc/overview.gif 16 | doc/pageheap.gif 17 | doc/pprof-test-big.gif 18 | doc/pprof-test.gif 19 | doc/pprof-vsnprintf-big.gif 20 | doc/pprof-vsnprintf.gif 21 | doc/pprof.1 22 | doc/pprof_remote_servers.html 23 | doc/spanmap.gif 24 | doc/t-test1.times.txt 25 | doc/tcmalloc-opspercpusec.vs.threads.1024.bytes.png 26 | doc/tcmalloc-opspercpusec.vs.threads.128.bytes.png 27 | doc/tcmalloc-opspercpusec.vs.threads.131072.bytes.png 28 | doc/tcmalloc-opspercpusec.vs.threads.16384.bytes.png 29 | doc/tcmalloc-opspercpusec.vs.threads.2048.bytes.png 30 | doc/tcmalloc-opspercpusec.vs.threads.256.bytes.png 31 | doc/tcmalloc-opspercpusec.vs.threads.32768.bytes.png 32 | doc/tcmalloc-opspercpusec.vs.threads.4096.bytes.png 33 | doc/tcmalloc-opspercpusec.vs.threads.512.bytes.png 34 | doc/tcmalloc-opspercpusec.vs.threads.64.bytes.png 35 | doc/tcmalloc-opspercpusec.vs.threads.65536.bytes.png 36 | doc/tcmalloc-opspercpusec.vs.threads.8192.bytes.png 37 | doc/tcmalloc-opspersec.vs.size.1.threads.png 38 | doc/tcmalloc-opspersec.vs.size.12.threads.png 39 | doc/tcmalloc-opspersec.vs.size.16.threads.png 40 | doc/tcmalloc-opspersec.vs.size.2.threads.png 41 | doc/tcmalloc-opspersec.vs.size.20.threads.png 42 | doc/tcmalloc-opspersec.vs.size.3.threads.png 43 | doc/tcmalloc-opspersec.vs.size.4.threads.png 44 | doc/tcmalloc-opspersec.vs.size.5.threads.png 45 | doc/tcmalloc-opspersec.vs.size.8.threads.png 46 | doc/tcmalloc.html 47 | doc/threadheap.gif 48 | -------------------------------------------------------------------------------- /gperftools-metalloc/packages/deb/libgperftools-dev.dirs: -------------------------------------------------------------------------------- 1 | usr/lib 2 | usr/lib/pkgconfig 3 | usr/include 4 | usr/include/google 5 | usr/include/gperftools 6 | -------------------------------------------------------------------------------- /gperftools-metalloc/packages/deb/libgperftools-dev.install: -------------------------------------------------------------------------------- 1 | usr/include/google/* 2 | usr/include/gperftools/* 3 | usr/lib/lib*.so 4 | usr/lib/lib*.a 5 | usr/lib/*.la 6 | usr/lib/pkgconfig/*.pc 7 | debian/tmp/usr/include/google/* 8 | debian/tmp/usr/include/gperftools/* 9 | debian/tmp/usr/lib/lib*.so 10 | debian/tmp/usr/lib/lib*.a 11 | debian/tmp/usr/lib/*.la 12 | debian/tmp/usr/lib/pkgconfig/*.pc 13 | -------------------------------------------------------------------------------- /gperftools-metalloc/packages/deb/libgperftools0.dirs: -------------------------------------------------------------------------------- 1 | usr/lib 2 | usr/bin 3 | -------------------------------------------------------------------------------- /gperftools-metalloc/packages/deb/libgperftools0.install: -------------------------------------------------------------------------------- 1 | usr/lib/lib*.so.* 2 | usr/bin/pprof* 3 | debian/tmp/usr/lib/lib*.so.* 4 | debian/tmp/usr/bin/pprof* 5 | -------------------------------------------------------------------------------- /gperftools-metalloc/packages/deb/libgperftools0.manpages: -------------------------------------------------------------------------------- 1 | doc/pprof.1 2 | -------------------------------------------------------------------------------- /gperftools-metalloc/packages/deb/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | # -*- makefile -*- 3 | # Sample debian/rules that uses debhelper. 4 | # This file was originally written by Joey Hess and Craig Small. 5 | # As a special exception, when this file is copied by dh-make into a 6 | # dh-make output file, you may use that output file without restriction. 7 | # This special exception was added by Craig Small in version 0.37 of dh-make. 8 | 9 | # Uncomment this to turn on verbose mode. 10 | #export DH_VERBOSE=1 11 | 12 | 13 | # These are used for cross-compiling and for saving the configure script 14 | # from having to guess our platform (since we know it already) 15 | DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE) 16 | DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE) 17 | 18 | 19 | CFLAGS = -Wall -g 20 | 21 | ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) 22 | CFLAGS += -O0 23 | else 24 | CFLAGS += -O2 25 | endif 26 | ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS))) 27 | INSTALL_PROGRAM += -s 28 | endif 29 | 30 | # shared library versions, option 1 31 | #version=2.0.5 32 | #major=2 33 | # option 2, assuming the library is created as src/.libs/libfoo.so.2.0.5 or so 34 | version=`ls src/.libs/lib*.so.* | \ 35 | awk '{if (match($$0,/[0-9]+\.[0-9]+\.[0-9]+$$/)) print substr($$0,RSTART)}'` 36 | major=`ls src/.libs/lib*.so.* | \ 37 | awk '{if (match($$0,/\.so\.[0-9]+$$/)) print substr($$0,RSTART+4)}'` 38 | 39 | config.status: configure 40 | dh_testdir 41 | # Add here commands to configure the package. 42 | CFLAGS="$(CFLAGS)" ./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info 43 | 44 | 45 | build: build-stamp 46 | build-stamp: config.status 47 | dh_testdir 48 | 49 | # Add here commands to compile the package. 50 | $(MAKE) 51 | 52 | touch build-stamp 53 | 54 | clean: 55 | dh_testdir 56 | dh_testroot 57 | rm -f build-stamp 58 | 59 | # Add here commands to clean up after the build process. 60 | -$(MAKE) distclean 61 | ifneq "$(wildcard /usr/share/misc/config.sub)" "" 62 | cp -f /usr/share/misc/config.sub config.sub 63 | endif 64 | ifneq "$(wildcard /usr/share/misc/config.guess)" "" 65 | cp -f /usr/share/misc/config.guess config.guess 66 | endif 67 | 68 | 69 | dh_clean 70 | 71 | install: build 72 | dh_testdir 73 | dh_testroot 74 | dh_clean -k 75 | dh_installdirs 76 | 77 | # Add here commands to install the package into debian/tmp 78 | $(MAKE) install DESTDIR=$(CURDIR)/debian/tmp 79 | 80 | 81 | # Build architecture-independent files here. 82 | binary-indep: build install 83 | # We have nothing to do by default. 84 | 85 | # Build architecture-dependent files here. 86 | binary-arch: build install 87 | dh_testdir 88 | dh_testroot 89 | dh_installchangelogs ChangeLog 90 | dh_installdocs 91 | dh_installexamples 92 | dh_install --sourcedir=debian/tmp 93 | # dh_installmenu 94 | # dh_installdebconf 95 | # dh_installlogrotate 96 | # dh_installemacsen 97 | # dh_installpam 98 | # dh_installmime 99 | # dh_installinit 100 | # dh_installcron 101 | # dh_installinfo 102 | dh_installman 103 | dh_link 104 | dh_strip 105 | dh_compress 106 | dh_fixperms 107 | # dh_perl 108 | # dh_python 109 | dh_makeshlibs 110 | dh_installdeb 111 | dh_shlibdeps 112 | dh_gencontrol 113 | dh_md5sums 114 | dh_builddeb 115 | 116 | binary: binary-indep binary-arch 117 | .PHONY: build clean binary-indep binary-arch binary install 118 | -------------------------------------------------------------------------------- /gperftools-metalloc/packages/rpm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | 3 | # Run this from the 'packages' directory, just under rootdir 4 | 5 | # We can only build rpm packages, if the rpm build tools are installed 6 | if [ \! -x /usr/bin/rpmbuild ] 7 | then 8 | echo "Cannot find /usr/bin/rpmbuild. Not building an rpm." 1>&2 9 | exit 0 10 | fi 11 | 12 | # Check the commandline flags 13 | PACKAGE="$1" 14 | VERSION="$2" 15 | fullname="${PACKAGE}-${VERSION}" 16 | archive=../$fullname.tar.gz 17 | 18 | if [ -z "$1" -o -z "$2" ] 19 | then 20 | echo "Usage: $0 " 1>&2 21 | exit 0 22 | fi 23 | 24 | # Double-check we're in the packages directory, just under rootdir 25 | if [ \! -r ../Makefile -a \! -r ../INSTALL ] 26 | then 27 | echo "Must run $0 in the 'packages' directory, under the root directory." 1>&2 28 | echo "Also, you must run \"make dist\" before running this script." 1>&2 29 | exit 0 30 | fi 31 | 32 | if [ \! -r "$archive" ] 33 | then 34 | echo "Cannot find $archive. Run \"make dist\" first." 1>&2 35 | exit 0 36 | fi 37 | 38 | # Create the directory where the input lives, and where the output should live 39 | RPM_SOURCE_DIR="/tmp/rpmsource-$fullname" 40 | RPM_BUILD_DIR="/tmp/rpmbuild-$fullname" 41 | 42 | trap 'rm -rf $RPM_SOURCE_DIR $RPM_BUILD_DIR; exit $?' EXIT SIGHUP SIGINT SIGTERM 43 | 44 | rm -rf "$RPM_SOURCE_DIR" "$RPM_BUILD_DIR" 45 | mkdir "$RPM_SOURCE_DIR" 46 | mkdir "$RPM_BUILD_DIR" 47 | 48 | cp "$archive" "$RPM_SOURCE_DIR" 49 | 50 | # rpmbuild -- as far as I can tell -- asks the OS what CPU it has. 51 | # This may differ from what kind of binaries gcc produces. dpkg 52 | # does a better job of this, so if we can run 'dpkg --print-architecture' 53 | # to get the build CPU, we use that in preference of the rpmbuild 54 | # default. 55 | target=`dpkg --print-architecture 2>/dev/null || echo ""` 56 | if [ -n "$target" ] 57 | then 58 | target=" --target $target" 59 | fi 60 | 61 | rpmbuild -bb rpm/rpm.spec $target \ 62 | --define "NAME $PACKAGE" \ 63 | --define "VERSION $VERSION" \ 64 | --define "_sourcedir $RPM_SOURCE_DIR" \ 65 | --define "_builddir $RPM_BUILD_DIR" \ 66 | --define "_rpmdir $RPM_SOURCE_DIR" 67 | 68 | # We put the output in a directory based on what system we've built for 69 | destdir=rpm-unknown 70 | if [ -r /etc/issue ] 71 | then 72 | grep "Red Hat.*release 7" /etc/issue >/dev/null 2>&1 && destdir=rh7 73 | grep "Red Hat.*release 8" /etc/issue >/dev/null 2>&1 && destdir=rh8 74 | grep "Red Hat.*release 9" /etc/issue >/dev/null 2>&1 && destdir=rh9 75 | grep "Fedora Core.*release 1" /etc/issue >/dev/null 2>&1 && destdir=fc1 76 | grep "Fedora Core.*release 2" /etc/issue >/dev/null 2>&1 && destdir=fc2 77 | grep "Fedora Core.*release 3" /etc/issue >/dev/null 2>&1 && destdir=fc3 78 | fi 79 | 80 | rm -rf "$destdir" 81 | mkdir -p "$destdir" 82 | # We want to get not only the main package but devel etc, hence the middle * 83 | mv "$RPM_SOURCE_DIR"/*/"${PACKAGE}"-*"${VERSION}"*.rpm "$destdir" 84 | 85 | echo 86 | echo "The rpm package file(s) are located in $PWD/$destdir" 87 | -------------------------------------------------------------------------------- /gperftools-metalloc/packages/rpm/rpm.spec: -------------------------------------------------------------------------------- 1 | %define RELEASE 1 2 | %define rel %{?CUSTOM_RELEASE} %{!?CUSTOM_RELEASE:%RELEASE} 3 | %define prefix /usr 4 | 5 | Name: %NAME 6 | Summary: Performance tools for C++ 7 | Version: %VERSION 8 | Release: %rel 9 | Group: Development/Libraries 10 | URL: http://code.google.com/p/gperftools/ 11 | License: BSD 12 | Vendor: gperftools Contributors 13 | Packager: gperftools Contributors 14 | Source: http://%{NAME}.googlecode.com/files/%{NAME}-%{VERSION}.tar.gz 15 | Distribution: Redhat 7 and above. 16 | Buildroot: %{_tmppath}/%{name}-root 17 | Prefix: %prefix 18 | 19 | %description 20 | The %name packages contains some utilities to improve and analyze the 21 | performance of C++ programs. This includes an optimized thread-caching 22 | malloc() and cpu and heap profiling utilities. 23 | 24 | %package devel 25 | Summary: Performance tools for C++ 26 | Group: Development/Libraries 27 | Requires: %{NAME} = %{VERSION} 28 | 29 | %description devel 30 | The %name-devel package contains static and debug libraries and header 31 | files for developing applications that use the %name package. 32 | 33 | %changelog 34 | * Mon Apr 20 2009 35 | - Change build rule to use a configure line more like '%configure' 36 | - Change install to use DESTDIR instead of prefix for configure 37 | - Use wildcards for doc/ and lib/ directories 38 | 39 | * Fri Mar 11 2005 40 | - First draft 41 | 42 | %prep 43 | %setup 44 | 45 | %build 46 | # I can't use '% configure', because it defines -m32 which breaks some 47 | # of the low-level atomicops files in this package. But I do take 48 | # as much from % configure (in /usr/lib/rpm/macros) as I can. 49 | ./configure --prefix=%{_prefix} --exec-prefix=%{_exec_prefix} --bindir=%{_bindir} --sbindir=%{_sbindir} --sysconfdir=%{_sysconfdir} --datadir=%{_datadir} --includedir=%{_includedir} --libdir=%{_libdir} --libexecdir=%{_libexecdir} --localstatedir=%{_localstatedir} --sharedstatedir=%{_sharedstatedir} --mandir=%{_mandir} --infodir=%{_infodir} 50 | make 51 | 52 | %install 53 | rm -rf $RPM_BUILD_ROOT 54 | make DESTDIR=$RPM_BUILD_ROOT install 55 | 56 | %clean 57 | rm -rf $RPM_BUILD_ROOT 58 | 59 | %files 60 | %defattr(-,root,root) 61 | 62 | %docdir %{prefix}/share/doc/%{NAME}-%{VERSION} 63 | %{prefix}/share/doc/%{NAME}-%{VERSION}/* 64 | 65 | %{_libdir}/*.so.* 66 | %{_bindir}/pprof 67 | %{_mandir}/man1/pprof.1* 68 | 69 | %files devel 70 | %defattr(-,root,root) 71 | 72 | %{_includedir}/google 73 | %{_includedir}/gperftools 74 | %{_libdir}/*.a 75 | %{_libdir}/*.la 76 | %{_libdir}/*.so 77 | %{_libdir}/pkgconfig/*.pc 78 | -------------------------------------------------------------------------------- /gperftools-metalloc/src/base/arm_instruction_set_select.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: Alexander Levitskiy 31 | // 32 | // Generalizes the plethora of ARM flavors available to an easier to manage set 33 | // Defs reference is at https://wiki.edubuntu.org/ARM/Thumb2PortingHowto 34 | 35 | #ifndef ARM_INSTRUCTION_SET_SELECT_H_ 36 | #define ARM_INSTRUCTION_SET_SELECT_H_ 37 | 38 | #if defined(__ARM_ARCH_8A__) 39 | # define ARMV8 1 40 | #endif 41 | 42 | #if defined(ARMV8) || \ 43 | defined(__ARM_ARCH_7__) || \ 44 | defined(__ARM_ARCH_7R__) || \ 45 | defined(__ARM_ARCH_7A__) 46 | # define ARMV7 1 47 | #endif 48 | 49 | #if defined(ARMV7) || \ 50 | defined(__ARM_ARCH_6__) || \ 51 | defined(__ARM_ARCH_6J__) || \ 52 | defined(__ARM_ARCH_6K__) || \ 53 | defined(__ARM_ARCH_6Z__) || \ 54 | defined(__ARM_ARCH_6T2__) || \ 55 | defined(__ARM_ARCH_6ZK__) 56 | # define ARMV6 1 57 | #endif 58 | 59 | #if defined(ARMV6) || \ 60 | defined(__ARM_ARCH_5T__) || \ 61 | defined(__ARM_ARCH_5E__) || \ 62 | defined(__ARM_ARCH_5TE__) || \ 63 | defined(__ARM_ARCH_5TEJ__) 64 | # define ARMV5 1 65 | #endif 66 | 67 | #if defined(ARMV5) || \ 68 | defined(__ARM_ARCH_4__) || \ 69 | defined(__ARM_ARCH_4T__) 70 | # define ARMV4 1 71 | #endif 72 | 73 | #if defined(ARMV4) || \ 74 | defined(__ARM_ARCH_3__) || \ 75 | defined(__ARM_ARCH_3M__) 76 | # define ARMV3 1 77 | #endif 78 | 79 | #if defined(ARMV3) || \ 80 | defined(__ARM_ARCH_2__) 81 | # define ARMV2 1 82 | #endif 83 | 84 | #endif // ARM_INSTRUCTION_SET_SELECT_H_ 85 | -------------------------------------------------------------------------------- /gperftools-metalloc/src/base/googleinit.h: -------------------------------------------------------------------------------- 1 | // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- 2 | // Copyright (c) 2005, Google Inc. 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // --- 32 | // Author: Jacob Hoffman-Andrews 33 | 34 | #ifndef _GOOGLEINIT_H 35 | #define _GOOGLEINIT_H 36 | 37 | #include "base/logging.h" 38 | 39 | class GoogleInitializer { 40 | public: 41 | typedef void (*VoidFunction)(void); 42 | GoogleInitializer(const char* name, VoidFunction ctor, VoidFunction dtor) 43 | : name_(name), destructor_(dtor) { 44 | RAW_VLOG(10, " constructing: %s\n", name_); 45 | if (ctor) 46 | ctor(); 47 | } 48 | ~GoogleInitializer() { 49 | RAW_VLOG(10, " destroying: %s\n", name_); 50 | if (destructor_) 51 | destructor_(); 52 | } 53 | 54 | private: 55 | const char* const name_; 56 | const VoidFunction destructor_; 57 | }; 58 | 59 | #define REGISTER_MODULE_INITIALIZER(name, body) \ 60 | namespace { \ 61 | static void google_init_module_##name () { body; } \ 62 | GoogleInitializer google_initializer_module_##name(#name, \ 63 | google_init_module_##name, NULL); \ 64 | } 65 | 66 | #define REGISTER_MODULE_DESTRUCTOR(name, body) \ 67 | namespace { \ 68 | static void google_destruct_module_##name () { body; } \ 69 | GoogleInitializer google_destructor_module_##name(#name, \ 70 | NULL, google_destruct_module_##name); \ 71 | } 72 | 73 | 74 | #endif /* _GOOGLEINIT_H */ 75 | -------------------------------------------------------------------------------- /gperftools-metalloc/src/base/linuxthreads.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2005-2007, Google Inc. 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are 6 | * met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above 11 | * copyright notice, this list of conditions and the following disclaimer 12 | * in the documentation and/or other materials provided with the 13 | * distribution. 14 | * * Neither the name of Google Inc. nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | * --- 31 | * Author: Markus Gutschke 32 | */ 33 | 34 | #ifndef _LINUXTHREADS_H 35 | #define _LINUXTHREADS_H 36 | 37 | /* Include thread_lister.h to get the interface that we implement for linux. 38 | */ 39 | 40 | /* We currently only support x86-32 and x86-64 on Linux. Porting to other 41 | * related platforms should not be difficult. 42 | */ 43 | #if (defined(__i386__) || defined(__x86_64__) || defined(__ARM_ARCH_3__) || \ 44 | defined(__mips__) || defined(__PPC__) || defined(__aarch64__)) && defined(__linux) 45 | 46 | /* Define the THREADS symbol to make sure that there is exactly one core dumper 47 | * built into the library. 48 | */ 49 | #define THREADS "Linux /proc" 50 | 51 | #endif 52 | 53 | #endif /* _LINUXTHREADS_H */ 54 | -------------------------------------------------------------------------------- /gperftools-metalloc/src/base/spinlock_internal.h: -------------------------------------------------------------------------------- 1 | // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- 2 | /* Copyright (c) 2010, Google Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are 7 | * met: 8 | * 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above 12 | * copyright notice, this list of conditions and the following disclaimer 13 | * in the documentation and/or other materials provided with the 14 | * distribution. 15 | * * Neither the name of Google Inc. nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | * --- 32 | * This file is an internal part spinlock.cc and once.cc 33 | * It may not be used directly by code outside of //base. 34 | */ 35 | 36 | #ifndef BASE_SPINLOCK_INTERNAL_H_ 37 | #define BASE_SPINLOCK_INTERNAL_H_ 38 | 39 | #include 40 | #include "base/basictypes.h" 41 | #include "base/atomicops.h" 42 | 43 | namespace base { 44 | namespace internal { 45 | 46 | void SpinLockWake(volatile Atomic32 *w, bool all); 47 | void SpinLockDelay(volatile Atomic32 *w, int32 value, int loop); 48 | 49 | } // namespace internal 50 | } // namespace base 51 | #endif 52 | -------------------------------------------------------------------------------- /gperftools-metalloc/src/base/spinlock_posix-inl.h: -------------------------------------------------------------------------------- 1 | // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- 2 | /* Copyright (c) 2009, Google Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are 7 | * met: 8 | * 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above 12 | * copyright notice, this list of conditions and the following disclaimer 13 | * in the documentation and/or other materials provided with the 14 | * distribution. 15 | * * Neither the name of Google Inc. nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | * --- 32 | * This file is a Posix-specific part of spinlock_internal.cc 33 | */ 34 | 35 | #include 36 | #include 37 | #ifdef HAVE_SCHED_H 38 | #include /* For sched_yield() */ 39 | #endif 40 | #include /* For nanosleep() */ 41 | 42 | namespace base { 43 | namespace internal { 44 | 45 | void SpinLockDelay(volatile Atomic32 *w, int32 value, int loop) { 46 | int save_errno = errno; 47 | if (loop == 0) { 48 | } else if (loop == 1) { 49 | sched_yield(); 50 | } else { 51 | struct timespec tm; 52 | tm.tv_sec = 0; 53 | tm.tv_nsec = base::internal::SuggestedDelayNS(loop); 54 | nanosleep(&tm, NULL); 55 | } 56 | errno = save_errno; 57 | } 58 | 59 | void SpinLockWake(volatile Atomic32 *w, bool all) { 60 | } 61 | 62 | } // namespace internal 63 | } // namespace base 64 | -------------------------------------------------------------------------------- /gperftools-metalloc/src/base/spinlock_win32-inl.h: -------------------------------------------------------------------------------- 1 | // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- 2 | /* Copyright (c) 2009, Google Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are 7 | * met: 8 | * 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above 12 | * copyright notice, this list of conditions and the following disclaimer 13 | * in the documentation and/or other materials provided with the 14 | * distribution. 15 | * * Neither the name of Google Inc. nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | * --- 32 | * This file is a Win32-specific part of spinlock_internal.cc 33 | */ 34 | 35 | 36 | #include 37 | 38 | namespace base { 39 | namespace internal { 40 | 41 | void SpinLockDelay(volatile Atomic32 *w, int32 value, int loop) { 42 | if (loop == 0) { 43 | } else if (loop == 1) { 44 | Sleep(0); 45 | } else { 46 | Sleep(base::internal::SuggestedDelayNS(loop) / 1000000); 47 | } 48 | } 49 | 50 | void SpinLockWake(volatile Atomic32 *w, bool all) { 51 | } 52 | 53 | } // namespace internal 54 | } // namespace base 55 | -------------------------------------------------------------------------------- /gperftools-metalloc/src/base/thread_lister.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2005-2007, Google Inc. 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are 6 | * met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above 11 | * copyright notice, this list of conditions and the following disclaimer 12 | * in the documentation and/or other materials provided with the 13 | * distribution. 14 | * * Neither the name of Google Inc. nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | * --- 31 | * Author: Markus Gutschke 32 | */ 33 | 34 | #include "config.h" 35 | #include /* needed for NULL on some powerpc platforms (?!) */ 36 | #ifdef HAVE_SYS_PRCTL 37 | # include 38 | #endif 39 | #include "base/thread_lister.h" 40 | #include "base/linuxthreads.h" 41 | /* Include other thread listers here that define THREADS macro 42 | * only when they can provide a good implementation. 43 | */ 44 | 45 | #ifndef THREADS 46 | 47 | /* Default trivial thread lister for single-threaded applications, 48 | * or if the multi-threading code has not been ported, yet. 49 | */ 50 | 51 | int TCMalloc_ListAllProcessThreads(void *parameter, 52 | ListAllProcessThreadsCallBack callback, ...) { 53 | int rc; 54 | va_list ap; 55 | pid_t pid; 56 | 57 | #ifdef HAVE_SYS_PRCTL 58 | int dumpable = prctl(PR_GET_DUMPABLE, 0); 59 | if (!dumpable) 60 | prctl(PR_SET_DUMPABLE, 1); 61 | #endif 62 | va_start(ap, callback); 63 | pid = getpid(); 64 | rc = callback(parameter, 1, &pid, ap); 65 | va_end(ap); 66 | #ifdef HAVE_SYS_PRCTL 67 | if (!dumpable) 68 | prctl(PR_SET_DUMPABLE, 0); 69 | #endif 70 | return rc; 71 | } 72 | 73 | int TCMalloc_ResumeAllProcessThreads(int num_threads, pid_t *thread_pids) { 74 | return 1; 75 | } 76 | 77 | #endif /* ifndef THREADS */ 78 | -------------------------------------------------------------------------------- /gperftools-metalloc/src/config_for_unittests.h: -------------------------------------------------------------------------------- 1 | // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- 2 | // Copyright (c) 2007, Google Inc. 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // --- 32 | // All Rights Reserved. 33 | // 34 | // Author: Craig Silverstein 35 | // 36 | // This file is needed for windows -- unittests are not part of the 37 | // perftools dll, but still want to include config.h just like the 38 | // dll does, so they can use internal tools and APIs for testing. 39 | // 40 | // The problem is that config.h declares PERFTOOLS_DLL_DECL to be 41 | // for exporting symbols, but the unittest needs to *import* symbols 42 | // (since it's not the dll). 43 | // 44 | // The solution is to have this file, which is just like config.h but 45 | // sets PERFTOOLS_DLL_DECL to do a dllimport instead of a dllexport. 46 | // 47 | // The reason we need this extra PERFTOOLS_DLL_DECL_FOR_UNITTESTS 48 | // variable is in case people want to set PERFTOOLS_DLL_DECL explicitly 49 | // to something other than __declspec(dllexport). In that case, they 50 | // may want to use something other than __declspec(dllimport) for the 51 | // unittest case. For that, we allow folks to define both 52 | // PERFTOOLS_DLL_DECL and PERFTOOLS_DLL_DECL_FOR_UNITTESTS explicitly. 53 | // 54 | // NOTE: This file is equivalent to config.h on non-windows systems, 55 | // which never defined PERFTOOLS_DLL_DECL_FOR_UNITTESTS and always 56 | // define PERFTOOLS_DLL_DECL to the empty string. 57 | 58 | #include "config.h" 59 | 60 | #undef PERFTOOLS_DLL_DECL 61 | #ifdef PERFTOOLS_DLL_DECL_FOR_UNITTESTS 62 | # define PERFTOOLS_DLL_DECL PERFTOOLS_DLL_DECL_FOR_UNITTESTS 63 | #else 64 | # define PERFTOOLS_DLL_DECL // if DLL_DECL_FOR_UNITTESTS isn't defined, use "" 65 | #endif 66 | -------------------------------------------------------------------------------- /gperftools-metalloc/src/getenv_safe.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- 2 | * Copyright (c) 2014, gperftools Contributors 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are 7 | * met: 8 | * 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above 12 | * copyright notice, this list of conditions and the following disclaimer 13 | * in the documentation and/or other materials provided with the 14 | * distribution. 15 | * * Neither the name of Google Inc. nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef GETENV_SAFE_H 33 | #define GETENV_SAFE_H 34 | 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | /* 40 | * This getenv function is safe to call before the C runtime is initialized. 41 | * On Windows, it utilizes GetEnvironmentVariable() and on unix it uses 42 | * /proc/self/environ instead calling getenv(). It's intended to be used in 43 | * routines that run before main(), when the state required for getenv() may 44 | * not be set up yet. In particular, errno isn't set up until relatively late 45 | * (after the pthreads library has a chance to make it threadsafe), and 46 | * getenv() doesn't work until then. 47 | * On some platforms, this call will utilize the same, static buffer for 48 | * repeated GetenvBeforeMain() calls. Callers should not expect pointers from 49 | * this routine to be long lived. 50 | * Note that on unix, /proc only has the environment at the time the 51 | * application was started, so this routine ignores setenv() calls/etc. Also 52 | * note it only reads the first 16K of the environment. 53 | * 54 | * NOTE: this is version of GetenvBeforeMain that's usable from 55 | * C. Implementation is in sysinfo.cc 56 | */ 57 | const char* TCMallocGetenvSafe(const char* name); 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /gperftools-metalloc/src/google/heap-checker.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2005, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | /* The code has moved to gperftools/. Use that include-directory for 31 | * new code. 32 | */ 33 | #ifdef __GNUC__ 34 | #warning "google/heap-checker.h is deprecated. Use gperftools/heap-checker.h instead" 35 | #endif 36 | #include 37 | -------------------------------------------------------------------------------- /gperftools-metalloc/src/google/heap-profiler.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2005, Google Inc. 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are 6 | * met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above 11 | * copyright notice, this list of conditions and the following disclaimer 12 | * in the documentation and/or other materials provided with the 13 | * distribution. 14 | * * Neither the name of Google Inc. nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | /* The code has moved to gperftools/. Use that include-directory for 32 | * new code. 33 | */ 34 | #ifdef __GNUC__ 35 | #warning "google/heap-profiler.h is deprecated. Use gperftools/heap-profiler.h instead" 36 | #endif 37 | #include 38 | -------------------------------------------------------------------------------- /gperftools-metalloc/src/google/malloc_extension.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2005, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | /* The code has moved to gperftools/. Use that include-directory for 31 | * new code. 32 | */ 33 | #ifdef __GNUC__ 34 | #warning "google/malloc_extension.h is deprecated. Use gperftools/malloc_extension.h instead" 35 | #endif 36 | #include 37 | -------------------------------------------------------------------------------- /gperftools-metalloc/src/google/malloc_extension_c.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2008, Google Inc. 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are 6 | * met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above 11 | * copyright notice, this list of conditions and the following disclaimer 12 | * in the documentation and/or other materials provided with the 13 | * distribution. 14 | * * Neither the name of Google Inc. nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | /* The code has moved to gperftools/. Use that include-directory for 32 | * new code. 33 | */ 34 | #ifdef __GNUC__ 35 | #warning "google/malloc_extension_c.h is deprecated. Use gperftools/malloc_extension_c.h instead" 36 | #endif 37 | #include 38 | -------------------------------------------------------------------------------- /gperftools-metalloc/src/google/malloc_hook.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2005, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | /* The code has moved to gperftools/. Use that include-directory for 31 | * new code. 32 | */ 33 | #ifdef __GNUC__ 34 | #warning "google/malloc_hook.h is deprecated. Use gperftools/malloc_hook.h instead" 35 | #endif 36 | #include 37 | -------------------------------------------------------------------------------- /gperftools-metalloc/src/google/malloc_hook_c.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2008, Google Inc. 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are 6 | * met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above 11 | * copyright notice, this list of conditions and the following disclaimer 12 | * in the documentation and/or other materials provided with the 13 | * distribution. 14 | * * Neither the name of Google Inc. nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | /* The code has moved to gperftools/. Use that include-directory for 32 | * new code. 33 | */ 34 | #ifdef __GNUC__ 35 | #warning "google/malloc_hook_c.h is deprecated. Use gperftools/malloc_hook_c.h instead" 36 | #endif 37 | #include 38 | -------------------------------------------------------------------------------- /gperftools-metalloc/src/google/profiler.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2005, Google Inc. 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are 6 | * met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above 11 | * copyright notice, this list of conditions and the following disclaimer 12 | * in the documentation and/or other materials provided with the 13 | * distribution. 14 | * * Neither the name of Google Inc. nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | /* The code has moved to gperftools/. Use that include-directory for 32 | * new code. 33 | */ 34 | #ifdef __GNUC__ 35 | #warning "google/profiler.h is deprecated. Use gperftools/profiler.h instead" 36 | #endif 37 | #include 38 | -------------------------------------------------------------------------------- /gperftools-metalloc/src/google/stacktrace.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2005, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | /* The code has moved to gperftools/. Use that include-directory for 31 | * new code. 32 | */ 33 | #ifdef __GNUC__ 34 | #warning "google/stacktrace.h is deprecated. Use gperftools/stacktrace.h instead" 35 | #endif 36 | #include 37 | -------------------------------------------------------------------------------- /gperftools-metalloc/src/google/tcmalloc.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2003, Google Inc. 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are 6 | * met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above 11 | * copyright notice, this list of conditions and the following disclaimer 12 | * in the documentation and/or other materials provided with the 13 | * distribution. 14 | * * Neither the name of Google Inc. nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | /* The code has moved to gperftools/. Use that include-directory for 32 | * new code. 33 | */ 34 | #ifdef __GNUC__ 35 | #warning "google/tcmalloc.h is deprecated. Use gperftools/tcmalloc.h instead" 36 | #endif 37 | #include 38 | -------------------------------------------------------------------------------- /gperftools-metalloc/src/maybe_threads.h: -------------------------------------------------------------------------------- 1 | // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- 2 | // Copyright (c) 2005, Google Inc. 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // --- 32 | // Author: Paul Menage 33 | 34 | //------------------------------------------------------------------- 35 | // Some wrappers for pthread functions so that we can be LD_PRELOADed 36 | // against non-pthreads apps. 37 | //------------------------------------------------------------------- 38 | 39 | #ifndef GOOGLE_MAYBE_THREADS_H_ 40 | #define GOOGLE_MAYBE_THREADS_H_ 41 | 42 | #ifdef HAVE_PTHREAD 43 | #include 44 | #endif 45 | 46 | int perftools_pthread_key_create(pthread_key_t *key, 47 | void (*destr_function) (void *)); 48 | int perftools_pthread_key_delete(pthread_key_t key); 49 | void *perftools_pthread_getspecific(pthread_key_t key); 50 | int perftools_pthread_setspecific(pthread_key_t key, void *val); 51 | int perftools_pthread_once(pthread_once_t *ctl, 52 | void (*init_routine) (void)); 53 | 54 | // Our wrapper for pthread_atfork. Does _nothing_ when there are no 55 | // threads. See static_vars.cc:SetupAtForkLocksHandler for only user 56 | // of this. 57 | void perftools_pthread_atfork(void (*before)(), 58 | void (*parent_after)(), 59 | void (*child_after)()); 60 | 61 | #endif /* GOOGLE_MAYBE_THREADS_H_ */ 62 | -------------------------------------------------------------------------------- /gperftools-metalloc/src/raw_printer.cc: -------------------------------------------------------------------------------- 1 | // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- 2 | // Copyright (c) 2008, Google Inc. 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // --- 32 | // Author: sanjay@google.com (Sanjay Ghemawat) 33 | 34 | #include 35 | #include 36 | #include 37 | #include "raw_printer.h" 38 | #include "base/logging.h" 39 | 40 | namespace base { 41 | 42 | RawPrinter::RawPrinter(char* buf, int length) 43 | : base_(buf), 44 | ptr_(buf), 45 | limit_(buf + length - 1) { 46 | RAW_DCHECK(length > 0, ""); 47 | *ptr_ = '\0'; 48 | *limit_ = '\0'; 49 | } 50 | 51 | void RawPrinter::Printf(const char* format, ...) { 52 | if (limit_ > ptr_) { 53 | va_list ap; 54 | va_start(ap, format); 55 | int avail = limit_ - ptr_; 56 | // We pass avail+1 to vsnprintf() since that routine needs room 57 | // to store the trailing \0. 58 | const int r = perftools_vsnprintf(ptr_, avail+1, format, ap); 59 | va_end(ap); 60 | if (r < 0) { 61 | // Perhaps an old glibc that returns -1 on truncation? 62 | ptr_ = limit_; 63 | } else if (r > avail) { 64 | // Truncation 65 | ptr_ = limit_; 66 | } else { 67 | ptr_ += r; 68 | } 69 | } 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /gperftools-metalloc/src/stack_trace_table.h: -------------------------------------------------------------------------------- 1 | // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- 2 | // Copyright (c) 2009, Google Inc. 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // --- 32 | // Author: Andrew Fikes 33 | // 34 | // Utility class for coalescing sampled stack traces. Not thread-safe. 35 | 36 | #ifndef TCMALLOC_STACK_TRACE_TABLE_H_ 37 | #define TCMALLOC_STACK_TRACE_TABLE_H_ 38 | 39 | #include 40 | #ifdef HAVE_STDINT_H 41 | #include // for uintptr_t 42 | #endif 43 | #include "common.h" 44 | 45 | namespace tcmalloc { 46 | 47 | class PERFTOOLS_DLL_DECL StackTraceTable { 48 | public: 49 | // REQUIRES: L < pageheap_lock 50 | StackTraceTable(); 51 | ~StackTraceTable(); 52 | 53 | // Adds stack trace "t" to table. 54 | // 55 | // REQUIRES: L >= pageheap_lock 56 | void AddTrace(const StackTrace& t); 57 | 58 | // Returns stack traces formatted per MallocExtension guidelines. 59 | // May return NULL on error. Clears state before returning. 60 | // 61 | // REQUIRES: L < pageheap_lock 62 | void** ReadStackTracesAndClear(); 63 | 64 | // Exposed for PageHeapAllocator 65 | struct Bucket { 66 | // Key 67 | uintptr_t hash; 68 | StackTrace trace; 69 | 70 | // Payload 71 | int count; 72 | Bucket* next; 73 | 74 | bool KeyEqual(uintptr_t h, const StackTrace& t) const; 75 | }; 76 | 77 | // For testing 78 | int depth_total() const { return depth_total_; } 79 | int bucket_total() const { return bucket_total_; } 80 | 81 | private: 82 | static const int kHashTableSize = 1 << 14; // => table_ is 128k 83 | 84 | bool error_; 85 | int depth_total_; 86 | int bucket_total_; 87 | Bucket** table_; 88 | }; 89 | 90 | } // namespace tcmalloc 91 | 92 | #endif // TCMALLOC_STACK_TRACE_TABLE_H_ 93 | -------------------------------------------------------------------------------- /gperftools-metalloc/src/symbolize.h: -------------------------------------------------------------------------------- 1 | // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- 2 | // Copyright (c) 2009, Google Inc. 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // --- 32 | // Author: Craig Silverstein 33 | 34 | #ifndef TCMALLOC_SYMBOLIZE_H_ 35 | #define TCMALLOC_SYMBOLIZE_H_ 36 | 37 | #include "config.h" 38 | #ifdef HAVE_STDINT_H 39 | #include // for uintptr_t 40 | #endif 41 | #include // for NULL 42 | #include 43 | 44 | using std::map; 45 | 46 | // SymbolTable encapsulates the address operations necessary for stack trace 47 | // symbolization. A common use-case is to Add() the addresses from one or 48 | // several stack traces to a table, call Symbolize() once and use GetSymbol() 49 | // to get the symbol names for pretty-printing the stack traces. 50 | class SymbolTable { 51 | public: 52 | SymbolTable() 53 | : symbol_buffer_(NULL) {} 54 | ~SymbolTable() { 55 | delete[] symbol_buffer_; 56 | } 57 | 58 | // Adds an address to the table. This may overwrite a currently known symbol 59 | // name, so Add() should not generally be called after Symbolize(). 60 | void Add(const void* addr); 61 | 62 | // Returns the symbol name for addr, if the given address was added before 63 | // the last successful call to Symbolize(). Otherwise may return an empty 64 | // c-string. 65 | const char* GetSymbol(const void* addr); 66 | 67 | // Obtains the symbol names for the addresses stored in the table and returns 68 | // the number of addresses actually symbolized. 69 | int Symbolize(); 70 | 71 | private: 72 | typedef map SymbolMap; 73 | 74 | // An average size of memory allocated for a stack trace symbol. 75 | static const int kSymbolSize = 1024; 76 | 77 | // Map from addresses to symbol names. 78 | SymbolMap symbolization_table_; 79 | 80 | // Pointer to the buffer that stores the symbol names. 81 | char *symbol_buffer_; 82 | }; 83 | 84 | #endif // TCMALLOC_SYMBOLIZE_H_ 85 | -------------------------------------------------------------------------------- /gperftools-metalloc/src/tcmalloc.h: -------------------------------------------------------------------------------- 1 | // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- 2 | // Copyright (c) 2007, Google Inc. 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // --- 32 | // Author: Craig Silverstein 33 | // 34 | // Some obscure memory-allocation routines may not be declared on all 35 | // systems. In those cases, we'll just declare them ourselves. 36 | // This file is meant to be used only internally, for unittests. 37 | 38 | #include 39 | 40 | #ifndef _XOPEN_SOURCE 41 | # define _XOPEN_SOURCE 600 // for posix_memalign 42 | #endif 43 | #include // for posix_memalign 44 | // FreeBSD has malloc.h, but complains if you use it 45 | #if defined(HAVE_MALLOC_H) && !defined(__FreeBSD__) 46 | #include // for memalign, valloc, pvalloc 47 | #endif 48 | 49 | // __THROW is defined in glibc systems. It means, counter-intuitively, 50 | // "This function will never throw an exception." It's an optional 51 | // optimization tool, but we may need to use it to match glibc prototypes. 52 | #ifndef __THROW // I guess we're not on a glibc system 53 | # define __THROW // __THROW is just an optimization, so ok to make it "" 54 | #endif 55 | 56 | #if !HAVE_CFREE_SYMBOL 57 | extern "C" void cfree(void* ptr) __THROW; 58 | #endif 59 | #if !HAVE_POSIX_MEMALIGN_SYMBOL 60 | extern "C" int posix_memalign(void** ptr, size_t align, size_t size) __THROW; 61 | #endif 62 | #if !HAVE_MEMALIGN_SYMBOL 63 | extern "C" void* memalign(size_t __alignment, size_t __size) __THROW; 64 | #endif 65 | #if !HAVE_VALLOC_SYMBOL 66 | extern "C" void* valloc(size_t __size) __THROW; 67 | #endif 68 | #if !HAVE_PVALLOC_SYMBOL 69 | extern "C" void* pvalloc(size_t __size) __THROW; 70 | #endif 71 | -------------------------------------------------------------------------------- /gperftools-metalloc/src/tcmalloc_guard.h: -------------------------------------------------------------------------------- 1 | // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- 2 | // Copyright (c) 2005, Google Inc. 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // --- 32 | // Author: Craig Silverstein 33 | // 34 | // We expose the TCMallocGuard class -- which initializes the tcmalloc 35 | // allocator -- so classes that need to be sure tcmalloc is loaded 36 | // before they do stuff -- notably heap-profiler -- can. To use this 37 | // create a static TCMallocGuard instance at the top of a file where 38 | // you need tcmalloc to be initialized before global constructors run. 39 | 40 | #ifndef TCMALLOC_TCMALLOC_GUARD_H_ 41 | #define TCMALLOC_TCMALLOC_GUARD_H_ 42 | 43 | class TCMallocGuard { 44 | public: 45 | TCMallocGuard(); 46 | ~TCMallocGuard(); 47 | }; 48 | 49 | #endif // TCMALLOC_TCMALLOC_GUARD_H_ 50 | -------------------------------------------------------------------------------- /gperftools-metalloc/src/tests/current_allocated_bytes_test.cc: -------------------------------------------------------------------------------- 1 | // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- 2 | // Copyright (c) 2011, Google Inc. 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | // --- 31 | // 32 | // Author: Craig Silverstein 33 | 34 | // This tests the accounting done by tcmalloc. When we allocate and 35 | // free a small buffer, the number of bytes used by the application 36 | // before the alloc+free should match the number of bytes used after. 37 | // However, the internal data structures used by tcmalloc will be 38 | // quite different -- new spans will have been allocated, etc. This 39 | // is, thus, a simple test that we account properly for the internal 40 | // data structures, so that we report the actual application-used 41 | // bytes properly. 42 | 43 | #include "config_for_unittests.h" 44 | #include 45 | #include 46 | #include 47 | #include "base/logging.h" 48 | 49 | const char kCurrent[] = "generic.current_allocated_bytes"; 50 | 51 | int main() { 52 | // We don't do accounting right when using debugallocation.cc, so 53 | // turn off the test then. TODO(csilvers): get this working too. 54 | #ifdef NDEBUG 55 | size_t before_bytes, after_bytes; 56 | MallocExtension::instance()->GetNumericProperty(kCurrent, &before_bytes); 57 | free(malloc(200)); 58 | MallocExtension::instance()->GetNumericProperty(kCurrent, &after_bytes); 59 | 60 | CHECK_EQ(before_bytes, after_bytes); 61 | #endif 62 | printf("PASS\n"); 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /gperftools-metalloc/src/tests/heap-checker_unittest.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Copyright (c) 2005, Google Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # * Neither the name of Google Inc. nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | # --- 33 | # Author: Craig Silverstein 34 | # 35 | # Runs the heap-checker unittest with various environment variables. 36 | # This is necessary because we turn on features like the heap profiler 37 | # and heap checker via environment variables. This test makes sure 38 | # they all play well together. 39 | 40 | # We expect BINDIR and PPROF_PATH to be set in the environment. 41 | # If not, we set them to some reasonable values 42 | BINDIR="${BINDIR:-.}" 43 | PPROF_PATH="${PPROF_PATH:-$BINDIR/src/pprof}" 44 | 45 | if [ "x$1" = "x-h" -o "$1" = "x--help" ]; then 46 | echo "USAGE: $0 [unittest dir] [path to pprof]" 47 | echo " By default, unittest_dir=$BINDIR, pprof_path=$PPROF_PATH" 48 | exit 1 49 | fi 50 | 51 | HEAP_CHECKER="${1:-$BINDIR/heap-checker_unittest}" 52 | PPROF_PATH="${2:-$PPROF_PATH}" 53 | 54 | TMPDIR=/tmp/heap_check_info 55 | rm -rf $TMPDIR || exit 2 56 | mkdir $TMPDIR || exit 3 57 | 58 | # $1: value of heap-check env. var. 59 | run_check() { 60 | export PPROF_PATH="$PPROF_PATH" 61 | [ -n "$1" ] && export HEAPCHECK="$1" || unset HEAPPROFILE 62 | 63 | echo -n "Testing $HEAP_CHECKER with HEAPCHECK=$1 ... " 64 | if $HEAP_CHECKER > $TMPDIR/output 2>&1; then 65 | echo "OK" 66 | else 67 | echo "FAILED" 68 | echo "Output from the failed run:" 69 | echo "----" 70 | cat $TMPDIR/output 71 | echo "----" 72 | exit 4 73 | fi 74 | 75 | # If we set HEAPPROFILE, then we expect it to actually have emitted 76 | # a profile. Check that it did. 77 | if [ -n "$HEAPPROFILE" ]; then 78 | [ -e "$HEAPPROFILE.0001.heap" ] || exit 5 79 | fi 80 | } 81 | 82 | run_check "" 83 | run_check "local" 84 | run_check "normal" 85 | run_check "strict" 86 | 87 | rm -rf $TMPDIR # clean up 88 | 89 | echo "PASS" 90 | -------------------------------------------------------------------------------- /gperftools-metalloc/src/tests/large_heap_fragmentation_unittest.cc: -------------------------------------------------------------------------------- 1 | // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- 2 | // Redistribution and use in source and binary forms, with or without 3 | // modification, are permitted provided that the following conditions are 4 | // met: 5 | // 6 | // * Redistributions of source code must retain the above copyright 7 | // notice, this list of conditions and the following disclaimer. 8 | // * Redistributions in binary form must reproduce the above 9 | // copyright notice, this list of conditions and the following disclaimer 10 | // in the documentation and/or other materials provided with the 11 | // distribution. 12 | // * Neither the name of Google Inc. nor the names of its 13 | // contributors may be used to endorse or promote products derived from 14 | // this software without specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | // This is a unit test for exercising fragmentation of large (over 1 29 | // meg) page spans. It makes sure that allocations/releases of 30 | // increasing memory chunks do not blowup memory 31 | // usage. See also https://code.google.com/p/gperftools/issues/detail?id=368 32 | 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | #include "base/logging.h" 39 | #include "common.h" 40 | #include 41 | 42 | 43 | int main (int argc, char** argv) { 44 | for (int pass = 1; pass <= 3; pass++) { 45 | size_t size = 100*1024*1024; 46 | while (size < 500*1024*1024) { 47 | void *ptr = malloc(size); 48 | free(ptr); 49 | size += 20000; 50 | 51 | size_t heap_size = static_cast(-1); 52 | MallocExtension::instance()->GetNumericProperty("generic.heap_size", 53 | &heap_size); 54 | 55 | 56 | CHECK_LT(heap_size, 1*1024*1024*1024); 57 | } 58 | } 59 | 60 | printf("PASS\n"); 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /gperftools-metalloc/src/tests/packed-cache_test.cc: -------------------------------------------------------------------------------- 1 | // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- 2 | // Copyright (c) 2007, Google Inc. 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // --- 32 | // Author: Geoff Pike 33 | 34 | #include 35 | #include "base/logging.h" 36 | #include "packed-cache-inl.h" 37 | 38 | static const int kHashbits = PackedCache<64, uint64>::kHashbits; 39 | 40 | // A basic sanity test. 41 | void PackedCacheTest_basic() { 42 | PackedCache<32, uint32> cache(0); 43 | CHECK_EQ(cache.GetOrDefault(0, 1), 0); 44 | cache.Put(0, 17); 45 | CHECK(cache.Has(0)); 46 | CHECK_EQ(cache.GetOrDefault(0, 1), 17); 47 | cache.Put(19, 99); 48 | CHECK(cache.Has(0) && cache.Has(19)); 49 | CHECK_EQ(cache.GetOrDefault(0, 1), 17); 50 | CHECK_EQ(cache.GetOrDefault(19, 1), 99); 51 | // Knock <0, 17> out by using a conflicting key. 52 | cache.Put(1 << kHashbits, 22); 53 | CHECK(!cache.Has(0)); 54 | CHECK_EQ(cache.GetOrDefault(0, 1), 1); 55 | CHECK_EQ(cache.GetOrDefault(1 << kHashbits, 1), 22); 56 | } 57 | 58 | int main(int argc, char **argv) { 59 | PackedCacheTest_basic(); 60 | 61 | printf("PASS\n"); 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /gperftools-metalloc/src/tests/raw_printer_test.cc: -------------------------------------------------------------------------------- 1 | // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- 2 | // Copyright 2009 Google Inc. All Rights Reserved. 3 | // Author: sanjay@google.com (Sanjay Ghemawat) 4 | // 5 | // Use of this source code is governed by a BSD-style license that can 6 | // be found in the LICENSE file. 7 | 8 | #include "raw_printer.h" 9 | #include 10 | #include 11 | #include "base/logging.h" 12 | 13 | using std::string; 14 | 15 | #define TEST(a, b) void TEST_##a##_##b() 16 | #define RUN_TEST(a, b) TEST_##a##_##b() 17 | 18 | TEST(RawPrinter, Empty) { 19 | char buffer[1]; 20 | base::RawPrinter printer(buffer, arraysize(buffer)); 21 | CHECK_EQ(0, printer.length()); 22 | CHECK_EQ(string(""), buffer); 23 | CHECK_EQ(0, printer.space_left()); 24 | printer.Printf("foo"); 25 | CHECK_EQ(string(""), string(buffer)); 26 | CHECK_EQ(0, printer.length()); 27 | CHECK_EQ(0, printer.space_left()); 28 | } 29 | 30 | TEST(RawPrinter, PartiallyFilled) { 31 | char buffer[100]; 32 | base::RawPrinter printer(buffer, arraysize(buffer)); 33 | printer.Printf("%s %s", "hello", "world"); 34 | CHECK_EQ(string("hello world"), string(buffer)); 35 | CHECK_EQ(11, printer.length()); 36 | CHECK_LT(0, printer.space_left()); 37 | } 38 | 39 | TEST(RawPrinter, Truncated) { 40 | char buffer[3]; 41 | base::RawPrinter printer(buffer, arraysize(buffer)); 42 | printer.Printf("%d", 12345678); 43 | CHECK_EQ(string("12"), string(buffer)); 44 | CHECK_EQ(2, printer.length()); 45 | CHECK_EQ(0, printer.space_left()); 46 | } 47 | 48 | TEST(RawPrinter, ExactlyFilled) { 49 | char buffer[12]; 50 | base::RawPrinter printer(buffer, arraysize(buffer)); 51 | printer.Printf("%s %s", "hello", "world"); 52 | CHECK_EQ(string("hello world"), string(buffer)); 53 | CHECK_EQ(11, printer.length()); 54 | CHECK_EQ(0, printer.space_left()); 55 | } 56 | 57 | int main(int argc, char **argv) { 58 | RUN_TEST(RawPrinter, Empty); 59 | RUN_TEST(RawPrinter, PartiallyFilled); 60 | RUN_TEST(RawPrinter, Truncated); 61 | RUN_TEST(RawPrinter, ExactlyFilled); 62 | printf("PASS\n"); 63 | return 0; // 0 means success 64 | } 65 | -------------------------------------------------------------------------------- /gperftools-metalloc/src/tests/sampling_test.cc: -------------------------------------------------------------------------------- 1 | // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- 2 | // Copyright (c) 2008, Google Inc. 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // --- 32 | // Author: Craig Silverstein 33 | // 34 | // This tests ReadStackTraces and ReadGrowthStackTraces. It does this 35 | // by doing a bunch of allocations and then calling those functions. 36 | // A driver shell-script can call this, and then call pprof, and 37 | // verify the expected output. The output is written to 38 | // argv[1].heap and argv[1].growth 39 | 40 | #include "config_for_unittests.h" 41 | #include 42 | #include 43 | #include 44 | #include "base/logging.h" 45 | #include 46 | 47 | using std::string; 48 | 49 | extern "C" void* AllocateAllocate() ATTRIBUTE_NOINLINE; 50 | 51 | extern "C" void* AllocateAllocate() { 52 | // The VLOG's are mostly to discourage inlining 53 | VLOG(1, "Allocating some more"); 54 | void* p = malloc(10000); 55 | VLOG(1, "Done allocating"); 56 | return p; 57 | } 58 | 59 | static void WriteStringToFile(const string& s, const string& filename) { 60 | FILE* fp = fopen(filename.c_str(), "w"); 61 | fwrite(s.data(), 1, s.length(), fp); 62 | fclose(fp); 63 | } 64 | 65 | int main(int argc, char** argv) { 66 | if (argc < 2) { 67 | fprintf(stderr, "USAGE: %s \n", argv[0]); 68 | exit(1); 69 | } 70 | for (int i = 0; i < 8000; i++) { 71 | AllocateAllocate(); 72 | } 73 | 74 | string s; 75 | MallocExtension::instance()->GetHeapSample(&s); 76 | WriteStringToFile(s, string(argv[1]) + ".heap"); 77 | 78 | s.clear(); 79 | MallocExtension::instance()->GetHeapGrowthStacks(&s); 80 | WriteStringToFile(s, string(argv[1]) + ".growth"); 81 | 82 | return 0; 83 | } 84 | -------------------------------------------------------------------------------- /gperftools-metalloc/src/tests/simple_compat_test.cc: -------------------------------------------------------------------------------- 1 | // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- 2 | // Copyright (c) 2012, Google Inc. 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // --- 32 | // Author: Craig Silverstein 33 | // 34 | // This just verifies that we can compile code that #includes stuff 35 | // via the backwards-compatibility 'google/' #include-dir. It does 36 | // not include config.h on purpose, to better simulate a perftools 37 | // client. 38 | 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | 51 | // We don't link in -lprofiler for this test, so be sure not to make 52 | // any function calls that require the cpu-profiler code. The 53 | // heap-profiler is ok. 54 | 55 | HeapLeakChecker::Disabler* heap_checker_h; 56 | void (*heap_profiler_h)(const char*) = &HeapProfilerStart; 57 | MallocExtension::Ownership malloc_extension_h; 58 | MallocExtension_Ownership malloc_extension_c_h; 59 | MallocHook::NewHook* malloc_hook_h; 60 | MallocHook_NewHook* malloc_hook_c_h; 61 | ProfilerOptions* profiler_h; 62 | int (*stacktrace_h)(void**, int, int) = &GetStackTrace; 63 | void* (*tcmalloc_h)(size_t) = &tc_new; 64 | 65 | int main(int argc, char** argv) { 66 | printf("PASS\n"); 67 | return 0; 68 | } 69 | -------------------------------------------------------------------------------- /gperftools-metalloc/src/tests/tcmalloc_unittest.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Copyright (c) 2013, Google Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # * Neither the name of Google Inc. nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | 32 | # --- 33 | # Author: Adhemerval Zanella 34 | # 35 | # Runs the tcmalloc_unittest with various environment variables. 36 | # This is necessary because tuning some environment variables 37 | # (TCMALLOC_TRANSFER_NUM_OBJ for instance) should not change program 38 | # behavior, just performance. 39 | 40 | BINDIR="${BINDIR:-.}" 41 | TCMALLOC_UNITTEST="${1:-$BINDIR/tcmalloc_unittest}" 42 | 43 | TMPDIR=/tmp/tcmalloc_unittest 44 | rm -rf $TMPDIR || exit 2 45 | mkdir $TMPDIR || exit 3 46 | 47 | run_unittest() { 48 | if $TCMALLOC_UNITTEST > $TMPDIR/output 2>&1; then 49 | echo "OK" 50 | else 51 | echo "FAILED" 52 | echo "Output from the failed run:" 53 | echo "----" 54 | cat $TMPDIR/output 55 | echo "----" 56 | exit 4 57 | fi 58 | } 59 | 60 | # $1: value of tcmalloc_unittest env. var. 61 | run_check_transfer_num_obj() { 62 | [ -n "$1" ] && export TCMALLOC_TRANSFER_NUM_OBJ="$1" 63 | 64 | echo -n "Testing $TCMALLOC_UNITTEST with TCMALLOC_TRANSFER_NUM_OBJ=$1 ... " 65 | run_unittest 66 | } 67 | 68 | run_check_transfer_num_obj "" 69 | run_check_transfer_num_obj "40" 70 | run_check_transfer_num_obj "4096" 71 | 72 | echo -n "Testing $TCMALLOC_UNITTEST with TCMALLOC_AGGRESSIVE_DECOMMIT=f ... " 73 | 74 | TCMALLOC_AGGRESSIVE_DECOMMIT=f run_unittest 75 | 76 | echo -n "Testing $TCMALLOC_UNITTEST with TCMALLOC_HEAP_LIMIT_MB=512 ... " 77 | 78 | TCMALLOC_HEAP_LIMIT_MB=512 run_unittest 79 | 80 | echo "PASS" 81 | -------------------------------------------------------------------------------- /gperftools-metalloc/src/tests/testutil.h: -------------------------------------------------------------------------------- 1 | // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- 2 | // Copyright (c) 2007, Google Inc. 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // --- 32 | // Author: Craig Silverstein 33 | 34 | #ifndef TCMALLOC_TOOLS_TESTUTIL_H_ 35 | #define TCMALLOC_TOOLS_TESTUTIL_H_ 36 | 37 | // Run a function in a thread of its own and wait for it to finish. 38 | // The function you pass in must have the signature 39 | // void MyFunction(); 40 | extern "C" void RunThread(void (*fn)()); 41 | 42 | // Run a function X times, in X threads, and wait for them all to finish. 43 | // The function you pass in must have the signature 44 | // void MyFunction(); 45 | extern "C" void RunManyThreads(void (*fn)(), int count); 46 | 47 | // The 'advanced' version: run a function X times, in X threads, and 48 | // wait for them all to finish. Give them all the specified stack-size. 49 | // (If you're curious why this takes a stacksize and the others don't, 50 | // it's because the one client of this fn wanted to specify stacksize. :-) ) 51 | // The function you pass in must have the signature 52 | // void MyFunction(int idx); 53 | // where idx is the index of the thread (which of the X threads this is). 54 | extern "C" void RunManyThreadsWithId(void (*fn)(int), int count, int stacksize); 55 | 56 | // When compiled 64-bit and run on systems with swap several unittests will end 57 | // up trying to consume all of RAM+swap, and that can take quite some time. By 58 | // limiting the address-space size we get sufficient coverage without blowing 59 | // out job limits. 60 | void SetTestResourceLimit(); 61 | 62 | #endif // TCMALLOC_TOOLS_TESTUTIL_H_ 63 | -------------------------------------------------------------------------------- /gperftools-metalloc/src/tests/thread_dealloc_unittest.cc: -------------------------------------------------------------------------------- 1 | // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- 2 | // Copyright (c) 2004, Google Inc. 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // --- 32 | // Author: Sanjay Ghemawat 33 | // 34 | // Check that we do not leak memory when cycling through lots of threads. 35 | 36 | #include "config_for_unittests.h" 37 | #include 38 | #ifdef HAVE_UNISTD_H 39 | #include // for sleep() 40 | #endif 41 | #include "base/logging.h" 42 | #include 43 | #include "tests/testutil.h" // for RunThread() 44 | 45 | // Size/number of objects to allocate per thread (1 MB per thread) 46 | static const int kObjectSize = 1024; 47 | static const int kNumObjects = 1024; 48 | 49 | // Number of threads to create and destroy 50 | static const int kNumThreads = 1000; 51 | 52 | // Allocate lots of stuff 53 | static void AllocStuff() { 54 | void** objects = new void*[kNumObjects]; 55 | for (int i = 0; i < kNumObjects; i++) { 56 | objects[i] = malloc(kObjectSize); 57 | } 58 | for (int i = 0; i < kNumObjects; i++) { 59 | free(objects[i]); 60 | } 61 | delete[] objects; 62 | } 63 | 64 | int main(int argc, char** argv) { 65 | static const int kDisplaySize = 1048576; 66 | char* display = new char[kDisplaySize]; 67 | 68 | for (int i = 0; i < kNumThreads; i++) { 69 | RunThread(&AllocStuff); 70 | 71 | if (((i+1) % 200) == 0) { 72 | fprintf(stderr, "Iteration: %d of %d\n", (i+1), kNumThreads); 73 | MallocExtension::instance()->GetStats(display, kDisplaySize); 74 | fprintf(stderr, "%s\n", display); 75 | } 76 | } 77 | delete[] display; 78 | 79 | printf("PASS\n"); 80 | #ifdef HAVE_UNISTD_H 81 | sleep(1); // Prevent exit race problem with glibc 82 | #endif 83 | return 0; 84 | } 85 | -------------------------------------------------------------------------------- /gperftools-metalloc/src/windows/TODO: -------------------------------------------------------------------------------- 1 | * Get heap-profile-table.cc using DeleteMatchingFiles 2 | * Get heap-profile-table.cc using FillProcSelfMaps, DumpProcSelfMaps 3 | * Play around with ExperimentalGetStackTrace 4 | * Support the windows-level memory-allocation functions? See 5 | /home/build/googleclient/earth/client/tools/memorytracking/client/memorytrace/src/memorytrace.cpp 6 | /home/build/googleclient/total_recall/common/sitestep/* 7 | http://www.internals.com/articles/apispy/apispy.htm 8 | http://www.wheaty.net/APISPY32.zip 9 | * Verify /proc/xxx/maps: 10 | http://www.geocities.com/wah_java_dotnet/procmap/index.html 11 | * Figure out how to edit the executable IAT so tcmalloc.dll is loaded first 12 | * Use QueryPerformanceCounter instead of GetTickCount() (also for sparsehash) 13 | 14 | ---- 15 | More info on windows-level memory-allocation functions: 16 | C runtime malloc 17 | LocalAlloc 18 | GlobalAlloc 19 | HeapAlloc 20 | VirtualAlloc 21 | mmap stuff 22 | 23 | malloc, LocalAlloc and GlobalAlloc call HeapAlloc, which calls 24 | VirtualAlloc when needed, which calls VirtualAllocEx (the __sbrk equiv?) 25 | 26 | siggi sez: If you want to do a generic job, you probably need to 27 | preserve the semantics of all of these Win32 calls: 28 | Heap32First 29 | Heap32ListFirst 30 | Heap32ListNext 31 | Heap32Next 32 | HeapAlloc 33 | HeapCompact 34 | HeapCreate 35 | HeapCreateTagsW 36 | HeapDestroy 37 | HeapExtend 38 | HeapFree 39 | HeapLock 40 | HeapQueryInformation 41 | HeapQueryTagW 42 | HeapReAlloc 43 | HeapSetInformation 44 | HeapSize 45 | HeapSummary 46 | HeapUnlock 47 | HeapUsage 48 | HeapValidate 49 | HeapWalk 50 | 51 | kernel32.dll export functions and nt.dll export functions: 52 | http://www.shorthike.com/svn/trunk/tools_win32/dm/lib/kernel32.def 53 | http://undocumented.ntinternals.net/ 54 | 55 | You can edit the executable IAT to have the patching DLL be the 56 | first one loaded. 57 | 58 | Most complete way to intercept system calls is patch the functions 59 | (not the IAT). 60 | 61 | Microsoft has somee built-in routines for heap-checking: 62 | http://support.microsoft.com/kb/268343 63 | 64 | ---- 65 | Itimer replacement: 66 | http://msdn2.microsoft.com/en-us/library/ms712713.aspx 67 | 68 | ---- 69 | Changes I've had to make to the project file: 70 | 71 | 0) When creating the project file, click on "no autogenerated files" 72 | 73 | --- For each project: 74 | 1) Alt-F7 -> General -> [pulldown "all configurations" ] -> Output Directory -> $(SolutionDir)$(ConfigurationName) 75 | 2) Alt-F7 -> General -> [pulldown "all configurations" ] -> Intermediate Directory -> $(ConfigurationName) 76 | 77 | --- For each .cc file: 78 | 1) Alt-F7 -> C/C++ -> General -> [pulldown "all configurations"] -> Additional Include Directives --> src/windows + src/ 79 | 2) Alt-F7 -> C/C++ -> Code Generation -> Runtime Library -> Multi-threaded, debug/release, DLL or not 80 | 81 | --- For DLL: 82 | 3) Alt-F7 -> Linker -> Input -> [pulldown "all configurations" ] -> Module Definition File -> src\windows\vc7and8.def 83 | --- For binaries depending on a DLL: 84 | 3) Right-click on project -> Project Dependencies -> [add dll] 85 | --- For static binaries (not depending on a DLL) 86 | 3) Alt-F7 -> C/C++ -> Command Line -> [pulldown "all configurations"] -> /D PERFTOOLS_DLL_DECL= 87 | -------------------------------------------------------------------------------- /gperftools-metalloc/src/windows/get_mangled_names.cc: -------------------------------------------------------------------------------- 1 | // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- 2 | // Copyright (c) 2008, Google Inc. 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | // 31 | // --- 32 | // Author: Craig Silverstein (opensource@google.com) 33 | 34 | // When you are porting perftools to a new compiler or architecture 35 | // (win64 vs win32) for instance, you'll need to change the mangled 36 | // symbol names for operator new and friends at the top of 37 | // patch_functions.cc. This file helps you do that. 38 | // 39 | // It does this by defining these functions with the proper signature. 40 | // All you need to do is compile this file and the run dumpbin on it. 41 | // (See http://msdn.microsoft.com/en-us/library/5x49w699.aspx for more 42 | // on dumpbin). To do this in MSVC, use the MSVC commandline shell: 43 | // http://msdn.microsoft.com/en-us/library/ms235639(VS.80).aspx) 44 | // 45 | // The run: 46 | // cl /c get_mangled_names.cc 47 | // dumpbin /symbols get_mangled_names.obj 48 | // 49 | // It will print out the mangled (and associated unmangled) names of 50 | // the 8 symbols you need to put at the top of patch_functions.cc 51 | 52 | #include // for size_t 53 | #include // for nothrow_t 54 | 55 | static char m; // some dummy memory so new doesn't return NULL. 56 | 57 | void* operator new(size_t size) { return &m; } 58 | void operator delete(void* p) throw() { } 59 | void* operator new[](size_t size) { return &m; } 60 | void operator delete[](void* p) throw() { } 61 | 62 | void* operator new(size_t size, const std::nothrow_t&) throw() { return &m; } 63 | void operator delete(void* p, const std::nothrow_t&) throw() { } 64 | void* operator new[](size_t size, const std::nothrow_t&) throw() { return &m; } 65 | void operator delete[](void* p, const std::nothrow_t&) throw() { } 66 | -------------------------------------------------------------------------------- /gperftools-metalloc/src/windows/google/tcmalloc.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2003, Google Inc. 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are 6 | * met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above 11 | * copyright notice, this list of conditions and the following disclaimer 12 | * in the documentation and/or other materials provided with the 13 | * distribution. 14 | * * Neither the name of Google Inc. nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | /* The code has moved to gperftools/. Use that include-directory for 32 | * new code. 33 | */ 34 | #include 35 | -------------------------------------------------------------------------------- /gperftools-metalloc/src/windows/ia32_modrm_map.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vusec/dangsan/72b3d813683359f8f3d3a168bca9d7c691340cef/gperftools-metalloc/src/windows/ia32_modrm_map.cc -------------------------------------------------------------------------------- /gperftools-metalloc/src/windows/ia32_opcode_map.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vusec/dangsan/72b3d813683359f8f3d3a168bca9d7c691340cef/gperftools-metalloc/src/windows/ia32_opcode_map.cc -------------------------------------------------------------------------------- /gperftools-metalloc/src/windows/mingw.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2 | /* Copyright (c) 2007, Google Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are 7 | * met: 8 | * 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above 12 | * copyright notice, this list of conditions and the following disclaimer 13 | * in the documentation and/or other materials provided with the 14 | * distribution. 15 | * * Neither the name of Google Inc. nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | * --- 32 | * Author: Craig Silverstein 33 | * 34 | * MinGW is an interesting mix of unix and windows. We use a normal 35 | * configure script, but still need the windows port.h to define some 36 | * stuff that MinGW doesn't support, like pthreads. 37 | */ 38 | 39 | #ifndef GOOGLE_PERFTOOLS_WINDOWS_MINGW_H_ 40 | #define GOOGLE_PERFTOOLS_WINDOWS_MINGW_H_ 41 | 42 | #ifdef __MINGW32__ 43 | 44 | // Older version of the mingw msvcrt don't define _aligned_malloc 45 | #if __MSVCRT_VERSION__ < 0x0700 46 | # define PERFTOOLS_NO_ALIGNED_MALLOC 1 47 | #endif 48 | 49 | // This must be defined before the windows.h is included. We need at 50 | // least 0x0400 for mutex.h to have access to TryLock, and at least 51 | // 0x0501 for patch_functions.cc to have access to GetModuleHandleEx. 52 | // (This latter is an optimization we could take out if need be.) 53 | #ifndef _WIN32_WINNT 54 | # define _WIN32_WINNT 0x0501 55 | #endif 56 | 57 | #define HAVE_SNPRINTF 1 58 | 59 | // Some mingw distributions have a pthreads wrapper, but it doesn't 60 | // work as well as native windows spinlocks (at least for us). So 61 | // pretend the pthreads wrapper doesn't exist, even when it does. 62 | #ifndef HAVE_PTHREAD_DESPITE_ASKING_FOR 63 | #undef HAVE_PTHREAD 64 | #endif 65 | 66 | #define HAVE_PID_T 67 | 68 | #include "windows/port.h" 69 | 70 | #endif /* __MINGW32__ */ 71 | 72 | #endif /* GOOGLE_PERFTOOLS_WINDOWS_MINGW_H_ */ 73 | -------------------------------------------------------------------------------- /gperftools-metalloc/src/windows/mini_disassembler.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vusec/dangsan/72b3d813683359f8f3d3a168bca9d7c691340cef/gperftools-metalloc/src/windows/mini_disassembler.h -------------------------------------------------------------------------------- /llvm-plugins/.gitignore: -------------------------------------------------------------------------------- 1 | /libplugins-opt.so 2 | /libplugins.so 3 | /obj/ 4 | 5 | -------------------------------------------------------------------------------- /llvm-plugins/CustomInliner.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * CustomInliner.cpp 3 | * 4 | * Created on: Nov 10, 2015 5 | * Author: haller 6 | */ 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | using namespace llvm; 14 | 15 | struct CustomInliner : public Inliner { 16 | static char ID; 17 | 18 | CustomInliner() : Inliner(ID) {} 19 | 20 | InlineCost getInlineCost(CallSite CS) { 21 | Function *Callee = CS.getCalledFunction(); 22 | const char *func_name = Callee->getName().str().c_str(); 23 | if (Callee && ISMETADATAFUNC(func_name) && strncmp(func_name, "dang_", 5)) { 24 | return InlineCost::getAlways(); 25 | } 26 | 27 | return InlineCost::getNever(); 28 | } 29 | 30 | 31 | }; 32 | 33 | char CustomInliner::ID = 0; 34 | static RegisterPass X("custominline", "Custom Inliner Pass", true, false); 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /llvm-plugins/FreeSentry.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _FREESENTRY_H_ 3 | #define _FREESENTRY_H_ 4 | 5 | using namespace llvm; 6 | 7 | // Namespace 8 | namespace llvm { 9 | Pass *createFreeSentry (); 10 | Pass *createFreeSentry (bool flag); 11 | Pass *createFreeSentryLoop (); 12 | Pass *createFreeSentryLoop (bool flag); 13 | Pass *createFSGraph (); 14 | Pass *createFSGraph (bool flag); 15 | } 16 | #endif 17 | -------------------------------------------------------------------------------- /llvm-plugins/Makefile: -------------------------------------------------------------------------------- 1 | CC=g++ 2 | INCLUDES=-I. -I../staticlib -I../metapagetable 3 | CFLAGS=-c -Werror -Wall -std=c++0x -g `llvm-config --cxxflags` -O0 4 | LDFLAGS=-g -shared 5 | TARGETDIR=. 6 | OBJDIR=$(TARGETDIR)/obj 7 | GOLDINSTDIR=$(METALLOC_HOME)/autosetup.dir/install/common 8 | LINKWITHGOLDFLAGS=-Wl,--no-undefined -L $(GOLDINSTDIR)/lib/ -l:LLVMgold.so -Wl,--rpath=$(GOLDINSTDIR)/lib 9 | 10 | EXE=$(TARGETDIR)/libplugins.so 11 | EXE2=$(TARGETDIR)/libplugins-opt.so 12 | 13 | SRCS := $(wildcard *.cpp) 14 | OBJS := $(patsubst %.cpp,$(OBJDIR)/%.o,$(SRCS)) 15 | DEPS := $(OBJS:.o=.d) 16 | 17 | all: $(EXE) $(EXE2) 18 | 19 | clean: 20 | rm $(OBJDIR)/*.o 21 | rm $(OBJDIR)/*.d 22 | rm $(EXE) 23 | rm $(EXE2) 24 | 25 | $(EXE): $(OBJS) $(TARGETDIR) 26 | $(CC) $(OBJS) $(LDFLAGS) $(LINKWITHGOLDFLAGS) -o $@ 27 | 28 | $(EXE2): $(OBJS) $(TARGETDIR) 29 | $(CC) $(OBJS) $(LDFLAGS) -o $@ 30 | 31 | -include $(DEPS) 32 | 33 | $(OBJDIR)/%.o: %.cpp $(OBJDIR) 34 | $(CC) $(INCLUDES) $(CFLAGS) -MMD -o $@ $< 35 | 36 | $(OBJDIR): 37 | mkdir -p $(OBJDIR) 38 | 39 | $(TARGETDIR): 40 | mkdir -p $(TARGETDIR) 41 | 42 | -------------------------------------------------------------------------------- /llvm-plugins/Utils.h: -------------------------------------------------------------------------------- 1 | #ifndef UTILS_H 2 | #define UTILS_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | extern llvm::cl::opt FixedCompression; 15 | extern llvm::cl::opt MetadataBytes; 16 | extern llvm::cl::opt DeepMetadata; 17 | extern llvm::cl::opt DeepMetadataBytes; 18 | 19 | class SafetyManager { 20 | public: 21 | const llvm::DataLayout *DL; 22 | llvm::ScalarEvolution *SE; 23 | 24 | SafetyManager(const llvm::DataLayout *DL, llvm::ScalarEvolution *SE) : DL(DL), SE(SE) {} 25 | 26 | unsigned long GetStaticAllocaAllocationSize(const llvm::AllocaInst *AI); 27 | unsigned long GetByvalArgumentSize(const llvm::Argument *Arg); 28 | bool IsSafeStackAlloca(const llvm::Value *AllocaPtr, unsigned long AllocaSize); 29 | void AccumulateSafeSideEffects(const llvm::Module *M, std::set &SafeSideEffects); 30 | void AccumulateSafeSideEffects(const llvm::Function *F, std::set &SafeSideEffects); 31 | void AccumulateUnsafeSideEffects(const llvm::Value *AllocaPtr, unsigned long AllocaSize, std::set > &UnsafeSideEffects); 32 | void AccumulateUnsafeSideEffects(const llvm::Function *F, std::map > > &UnsafeSideEffects); 33 | void AccumulateUnsafeSideEffects(const llvm::Module *M, std::map > > &UnsafeSideEffects); 34 | private: 35 | bool DoesContainPointer(const llvm::Type *T); 36 | bool IsAccessSafe(llvm::Value *Addr, unsigned long AccessSize, 37 | const llvm::Value *AllocaPtr, unsigned long AllocaSize); 38 | bool IsMemIntrinsicSafe(const llvm::MemIntrinsic *MI, const llvm::Use &U, 39 | const llvm::Value *AllocaPtr, 40 | unsigned long AllocaSize); 41 | void AccumulateSideEffects(const llvm::Value *AllocaPtr, std::set &SideEffects); 42 | }; 43 | 44 | #endif /* !UTILS_H */ 45 | -------------------------------------------------------------------------------- /metapagetable/.gitignore: -------------------------------------------------------------------------------- 1 | /.libs/ 2 | /libmetapagetable.la 3 | /linker-options 4 | /metapagetable.h 5 | /obj/ 6 | 7 | -------------------------------------------------------------------------------- /metapagetable/Makefile: -------------------------------------------------------------------------------- 1 | PAGESIZE:= $(shell getconf PAGESIZE) 2 | CC=libtool --tag=CC --mode=compile gcc -prefer-pic 3 | LINKER=libtool --tag=CC --mode=link gcc 4 | INCLUDES=-I. -I../gperftools-metalloc/src/ -I$(OBJDIR) 5 | CFLAGS=-fPIC -c -Werror -Wall -O3 -std=gnu11 -DSYSTEM_PAGESIZE=$(PAGESIZE) 6 | LDFLAGS=-static 7 | OBJDIR=obj 8 | 9 | EXE=$(OBJDIR)/libmetapagetable.la 10 | 11 | SRCS := $(wildcard *.c) 12 | OBJS := $(patsubst %.c,$(OBJDIR)/%.lo,$(SRCS)) 13 | DEPS := $(OBJS:.lo=.d) 14 | 15 | all: $(OBJDIR)/metapagetable.h $(OBJDIR)/metapagetable_core.h $(EXE) 16 | 17 | clean: 18 | rm -rf $(OBJDIR) 19 | rm -f linker-options 20 | rm -f metapagetable.h 21 | 22 | $(EXE): $(OBJS) directories 23 | $(LINKER) $(OBJS) $(LDFLAGS) -o $@ 24 | #ar crv $@ $(OBJS) 25 | #ranlib $@ 26 | 27 | -include $(DEPS) 28 | 29 | $(OBJDIR)/%.lo: %.c directories 30 | $(CC) $(INCLUDES) $(CFLAGS) -MT $@ -MMD -o $@ $< 31 | 32 | $(OBJDIR)/metapagetable.h: metapagetable.h.in linker-options.in config_metapagetable.cmake directories 33 | rm -f metapagetable.h 34 | rm -f linker-options 35 | rm -f $(OBJDIR)/metapagetable.h 36 | rm -f $(OBJDIR)/linker-options 37 | cmake $(METALLOC_OPTIONS) -P ./config_metapagetable.cmake 38 | mv linker-options $(OBJDIR) 39 | mv metapagetable.h $(OBJDIR) 40 | 41 | $(OBJDIR)/metapagetable_core.h: metapagetable_core.h directories 42 | cp metapagetable_core.h $(OBJDIR) 43 | 44 | touch_config: 45 | touch metapagetable.h.in 46 | touch linker-options.in 47 | 48 | config: touch_config 49 | $(MAKE) $(OBJDIR)/metapagetable.h 50 | 51 | directories: 52 | mkdir -p $(OBJDIR) 53 | 54 | 55 | -------------------------------------------------------------------------------- /metapagetable/config_metapagetable.cmake: -------------------------------------------------------------------------------- 1 | if (NOT DEFINED FIXEDCOMPRESSION) 2 | set(FIXEDCOMPRESSION false) 3 | endif () 4 | if (NOT DEFINED METADATABYTES) 5 | set(METADATABYTES 8) 6 | endif () 7 | if (NOT DEFINED DEEPMETADATA) 8 | set(DEEPMETADATA false) 9 | else() 10 | if (DEEPMETADATA AND FIXEDCOMPRESSION) 11 | message(FATAL_ERROR "Deep Metadata not supported with fixed compression") 12 | endif () 13 | if (DEEPMETADATA AND NOT METADATABYTES EQUAL 8) 14 | message(FATAL_ERROR "Deep Metadata requires 8 byte Metadata") 15 | endif () 16 | endif () 17 | if (NOT DEFINED DEEPMETADATABYTES) 18 | set(DEEPMETADATABYTES 8) 19 | else () 20 | if (NOT DEEPMETADATA) 21 | message(FATAL_ERROR "Trying to set Deep Metadata size when none requested") 22 | endif () 23 | endif () 24 | 25 | if (NOT DEFINED ALLOC_SIZE_HOOK) 26 | set(ALLOC_SIZE_HOOK_ENABLED 0) 27 | else () 28 | set(ALLOC_SIZE_HOOK_ENABLED 1) 29 | endif () 30 | 31 | if (NOT DEFINED ALLOC_HOOK) 32 | set(ALLOC_HOOK default_alloc_hook) 33 | endif () 34 | 35 | if (NOT DEFINED RESIZE_HOOK) 36 | set(RESIZE_HOOK_ENABLED 0) 37 | else () 38 | set(RESIZE_HOOK_ENABLED 1) 39 | endif () 40 | 41 | if (NOT DEFINED FREE_HOOK) 42 | set(FREE_HOOK_ENABLED 0) 43 | else () 44 | set(FREE_HOOK_ENABLED 1) 45 | endif () 46 | 47 | configure_file(metapagetable.h.in metapagetable.h) 48 | configure_file(linker-options.in linker-options) 49 | -------------------------------------------------------------------------------- /metapagetable/danghooks.c: -------------------------------------------------------------------------------- 1 | /* This function increases size of memory 2 | * allocation request by one byte to avoid 3 | * off-by-one legitimate out-of-bound. 4 | */ 5 | unsigned long 6 | dang_alloc_size_hook(unsigned long size) { 7 | return (size + 1); 8 | } 9 | -------------------------------------------------------------------------------- /metapagetable/defaulthooks.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | typedef uint8_t meta1; 6 | typedef uint16_t meta2; 7 | typedef uint32_t meta4; 8 | typedef uint64_t meta8; 9 | 10 | static void set_metadata(void *ptr, void *deepmetadata, unsigned long size, unsigned char value) { 11 | if (!FLAGS_METALLOC_FIXEDCOMPRESSION) { 12 | unsigned long page = (unsigned long)ptr / METALLOC_PAGESIZE; 13 | unsigned long entry = pageTable[page]; 14 | unsigned long alignment = entry & 0xFF; 15 | char *metabase = (char*)(entry >> 8); 16 | char *metaptr = metabase + ((((unsigned long)ptr - (page * METALLOC_PAGESIZE)) >> alignment) * FLAGS_METALLOC_METADATABYTES); 17 | unsigned long metasize = ((size + (1 << (alignment)) - 1) >> alignment); 18 | if (FLAGS_METALLOC_DEEPMETADATA) { 19 | unsigned long *metadata_loc = (unsigned long*)deepmetadata; 20 | for (unsigned long i = 0; i < metasize; ++i) 21 | ((unsigned long*)metaptr)[i] = (unsigned long)metadata_loc; 22 | if (metadata_loc != 0) { 23 | for (unsigned long j = 0; j < FLAGS_METALLOC_DEEPMETADATABYTES / sizeof(unsigned long); ++j) 24 | metadata_loc[j] = value; 25 | } 26 | } else { 27 | for (unsigned long i = 0; i < metasize; ++i) 28 | for (unsigned long j = 0; j < FLAGS_METALLOC_METADATABYTES; ++j) 29 | metaptr[i * FLAGS_METALLOC_METADATABYTES + j] = value; 30 | } 31 | } else { 32 | unsigned long pos = (unsigned long)ptr / METALLOC_FIXEDSIZE; 33 | char *metaptr = ((char*)pageTable) + pos; 34 | unsigned long metasize = ((size + METALLOC_FIXEDSIZE - 1) / METALLOC_FIXEDSIZE); 35 | for (unsigned long i = 0; i < metasize; ++i) 36 | for (unsigned long j = 0; j < FLAGS_METALLOC_METADATABYTES; ++j) 37 | metaptr[i * FLAGS_METALLOC_METADATABYTES + j] = value; 38 | } 39 | } 40 | 41 | void default_alloc_hook(void* ptr, void *deepmetadata, unsigned long content_size, unsigned long allocation_size) { 42 | set_metadata(ptr, deepmetadata, allocation_size, 0); 43 | } 44 | -------------------------------------------------------------------------------- /metapagetable/linker-options.in: -------------------------------------------------------------------------------- 1 | -Wl,-plugin-opt=-METALLOC_FIXEDCOMPRESSION=${FIXEDCOMPRESSION} 2 | -Wl,-plugin-opt=-METALLOC_METADATABYTES=${METADATABYTES} 3 | -Wl,-plugin-opt=-METALLOC_DEEPMETADATA=${DEEPMETADATA} 4 | -Wl,-plugin-opt=-METALLOC_DEEPMETADATABYTES=${DEEPMETADATABYTES} 5 | -------------------------------------------------------------------------------- /metapagetable/metapagetable.h.in: -------------------------------------------------------------------------------- 1 | #ifndef METAPAGETABLE_H 2 | #define METAPAGETABLE_H 3 | 4 | #include 5 | 6 | #include 7 | 8 | #define FLAGS_METALLOC_FIXEDCOMPRESSION ${FIXEDCOMPRESSION} 9 | #define FLAGS_METALLOC_METADATABYTES ${METADATABYTES} 10 | #define FLAGS_METALLOC_DEEPMETADATA ${DEEPMETADATA} 11 | #define FLAGS_METALLOC_DEEPMETADATABYTES ${DEEPMETADATABYTES} 12 | 13 | extern void (*metalloc_malloc_prehook)(unsigned long size); 14 | extern void (*metalloc_malloc_posthook)(unsigned long ptr, unsigned long size); 15 | extern void (*metalloc_free_prehook)(unsigned long ptr, unsigned long size); 16 | extern void (*metalloc_free_posthook)(unsigned long ptr); 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | #if ${ALLOC_SIZE_HOOK_ENABLED} == 1 23 | #define METALLOC_ALLOC_SIZE_HOOK ${ALLOC_SIZE_HOOK} 24 | 25 | unsigned long METALLOC_ALLOC_SIZE_HOOK(unsigned long size); 26 | 27 | #endif 28 | 29 | #define METALLOC_ALLOC_HOOK ${ALLOC_HOOK} 30 | 31 | void METALLOC_ALLOC_HOOK(void *ptr, void *deepmetadata, unsigned long content_size, unsigned long allocation_size); 32 | 33 | #if ${RESIZE_HOOK_ENABLED} == 1 34 | #define METALLOC_RESIZE_HOOK ${RESIZE_HOOK} 35 | 36 | void METALLOC_RESIZE_HOOK(void *ptr, unsigned long content_size, unsigned long allocation_size); 37 | 38 | #endif 39 | 40 | #if ${FREE_HOOK_ENABLED} == 1 41 | #define METALLOC_FREE_HOOK ${FREE_HOOK} 42 | 43 | void METALLOC_FREE_HOOK(void *ptr, unsigned long size); 44 | 45 | #endif 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif /* !METAPAGETABLE_H */ 52 | -------------------------------------------------------------------------------- /metapagetable/metapagetable_core.h: -------------------------------------------------------------------------------- 1 | #ifndef METAPAGETABLE_CORE_H 2 | #define METAPAGETABLE_CORE_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #define METALLOC_PAGESHIFT 12 9 | #define METALLOC_PAGESIZE (1 << METALLOC_PAGESHIFT) 10 | 11 | #define METALLOC_FIXEDSHIFT 3 12 | #define METALLOC_FIXEDSIZE (1 << METALLOC_FIXEDSHIFT) 13 | 14 | //extern unsigned long pageTable[]; 15 | #define pageTable ((unsigned long*)(0x400000000000)) 16 | extern int is_fixed_compression(); 17 | extern void page_table_init(); 18 | extern void* allocate_metadata(unsigned long size, unsigned long alignment); 19 | extern void deallocate_metadata(void *ptr, unsigned long size, unsigned long alignment); 20 | extern void set_metapagetable_entries(void *ptr, unsigned long size, void *metaptr, int alignment); 21 | extern unsigned long get_metapagetable_entry(void *ptr); 22 | extern void allocate_metapagetable_entries(void *ptr, unsigned long size); 23 | extern void deallocate_metapagetable_entries(void *ptr, unsigned long size); 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | 29 | #endif /* !METAPAGETABLE_CORE_H */ 30 | -------------------------------------------------------------------------------- /nothp/.gitignore: -------------------------------------------------------------------------------- 1 | nothp 2 | -------------------------------------------------------------------------------- /nothp/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-O3 -Wall 2 | 3 | .PHONY: all clean 4 | 5 | all: nothp 6 | 7 | clean: 8 | rm -f nothp *.o 9 | 10 | nothp: nothp.c 11 | -------------------------------------------------------------------------------- /nothp/nothp.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main(int argc, char **argv) { 7 | if (prctl(PR_SET_THP_DISABLE, 1, 0, 0, 0) != 0) { 8 | perror("nothp: prctl failed"); 9 | return -1; 10 | } 11 | 12 | execvp(argv[1], argv + 1); 13 | perror("nothp: exec failed"); 14 | return -1; 15 | } 16 | -------------------------------------------------------------------------------- /patches/GPERFTOOLS_SPEEDUP.patch: -------------------------------------------------------------------------------- 1 | From 49ff49634debdcc13ebf2e00b8ceb53b3d8c9f72 Mon Sep 17 00:00:00 2001 2 | From: Istvan Haller 3 | Date: Thu, 17 Mar 2016 13:44:17 +0100 4 | Subject: [PATCH] Performance fix for SPEC. 5 | 6 | --- 7 | src/common.h | 4 ++-- 8 | src/tcmalloc.cc | 3 ++- 9 | 2 files changed, 4 insertions(+), 3 deletions(-) 10 | 11 | diff --git a/src/common.h b/src/common.h 12 | index c3484d3..15d7ee7 100644 13 | --- a/src/common.h 14 | +++ b/src/common.h 15 | @@ -91,13 +91,13 @@ static const size_t kPageShift = 16; 16 | static const size_t kNumClasses = kBaseClasses + 73; 17 | #else 18 | static const size_t kPageShift = 13; 19 | -static const size_t kNumClasses = kBaseClasses + 79; 20 | +static const size_t kNumClasses = kBaseClasses + 79 + 32; 21 | #endif 22 | 23 | static const size_t kMaxThreadCacheSize = 4 << 20; 24 | 25 | static const size_t kPageSize = 1 << kPageShift; 26 | -static const size_t kMaxSize = 256 * 1024; 27 | +static const size_t kMaxSize = 256 * 1024 * 2;; 28 | static const size_t kAlignment = 8; 29 | static const size_t kLargeSizeClass = 0; 30 | // For all span-lengths < kMaxPages we keep an exact-size list. 31 | diff --git a/src/tcmalloc.cc b/src/tcmalloc.cc 32 | index b7d1913..387ba76 100644 33 | --- a/src/tcmalloc.cc 34 | +++ b/src/tcmalloc.cc 35 | @@ -1211,7 +1211,8 @@ ALWAYS_INLINE void* do_calloc(size_t n, size_t elem_size) { 36 | 37 | void* result = do_malloc_or_cpp_alloc(size); 38 | if (result != NULL) { 39 | - memset(result, 0, size); 40 | + if (size <= kMaxSize) 41 | + memset(result, 0, size); 42 | } 43 | return result; 44 | } 45 | -- 46 | 1.7.9.5 47 | 48 | -------------------------------------------------------------------------------- /patches/SPEC-CPU2006-dealII-stddef.patch: -------------------------------------------------------------------------------- 1 | --- ./benchspec/CPU2006/447.dealII/src/include/lac/block_vector.h.orig 2016-11-17 21:40:18.088695507 +0100 2 | +++ ./benchspec/CPU2006/447.dealII/src/include/lac/block_vector.h 2016-11-17 21:37:42.698760418 +0100 3 | @@ -14,6 +14,7 @@ 4 | #define __deal2__block_vector_h 5 | 6 | 7 | +#include 8 | #include 9 | #include 10 | #include 11 | -------------------------------------------------------------------------------- /patches/perl-makedepend.patch: -------------------------------------------------------------------------------- 1 | --- perl-5.8.8.orig/makedepend.SH 2015-11-10 16:03:47.574265920 +0100 2 | +++ perl-5.8.8/makedepend.SH 2015-11-10 16:04:06.578719285 +0100 3 | @@ -167,6 +167,7 @@ 4 | -e '/^#.*/d' \ 5 | -e '/^#.*/d' \ 6 | -e '/^#.*/d' \ 7 | + -e '/^#.*/d' \ 8 | -e '/^#.*"-"/d' \ 9 | -e '/: file path prefix .* never used$/d' \ 10 | -e 's#\.[0-9][0-9]*\.c#'"$file.c#" \ 11 | -------------------------------------------------------------------------------- /patches/perl-pagesize.patch: -------------------------------------------------------------------------------- 1 | --- perl-5.8.8.orig/ext/IPC/SysV/SysV.xs 2015-11-10 20:34:41.752275825 +0100 2 | +++ perl-5.8.8/ext/IPC/SysV/SysV.xs 2015-11-10 20:35:06.302848271 +0100 3 | @@ -4,7 +4,7 @@ 4 | 5 | #include 6 | #ifdef __linux__ 7 | -# include 8 | +#define PAGE_SIZE (getpagesize()) 9 | #endif 10 | #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM) 11 | #ifndef HAS_SEM 12 | -------------------------------------------------------------------------------- /staticlib/.gitignore: -------------------------------------------------------------------------------- 1 | /libmetadata.a 2 | /obj/ 3 | 4 | -------------------------------------------------------------------------------- /staticlib/Dangling/.gitignore: -------------------------------------------------------------------------------- 1 | /lib/ 2 | -------------------------------------------------------------------------------- /staticlib/Dangling/README: -------------------------------------------------------------------------------- 1 | There are two different implementations for the pointer tracking. 2 | 3 | Project Structure: 4 | Each design has its own source files. Whenever common code is required it will be taken out into new source file. 5 | 6 | 1) Based on FreeSentry 7 | - This design is implemented to check the benifit of Metalloc 8 | - Gain more understanding and find new issues. 9 | Files : 10 | pointer_track.c, pointer_track.h 11 | 12 | 2) per-Thread log model 13 | - This design is based on having per-Thread per-Object logs 14 | - This avoids lock contention or performance degradation introduced by locking 15 | - This should give huge benefit in multi-threaded environment. 16 | -------------------------------------------------------------------------------- /staticlib/Dangling/dang_san.h: -------------------------------------------------------------------------------- 1 | #ifndef DANG_SAN_H 2 | #define DANG_SAN_H 3 | 4 | /* initial size of hash table once static/dynamic logs are exhausted */ 5 | #ifndef DANG_HASHTABLE_INITSIZE 6 | #define DANG_HASHTABLE_INITSIZE 128 7 | #endif 8 | 9 | /* hash table growth factor once load fraction is too high */ 10 | #ifndef DANG_HASHTABLE_GROWFACTOR 11 | #define DANG_HASHTABLE_GROWFACTOR 4 12 | #endif 13 | 14 | /* allow hash table load to be at most 1/DANG_HASHTABLE_MAXLOADFRAC */ 15 | #ifndef DANG_HASHTABLE_MAXLOADFRAC 16 | #define DANG_HASHTABLE_MAXLOADFRAC 2 17 | #endif 18 | 19 | /* skip this many entries in hash table on collision */ 20 | #ifndef DANG_HASHTABLE_SKIP 21 | #define DANG_HASHTABLE_SKIP 13 22 | #endif 23 | 24 | /* look back in static log to avoid duplicates */ 25 | #ifndef DANG_STATICLOG_LOOKBACK 26 | #define DANG_STATICLOG_LOOKBACK 4 27 | #endif 28 | 29 | /* look back in static log to avoid duplicates */ 30 | #ifndef DANG_OBJLOG_ENTRIES 31 | #define DANG_OBJLOG_ENTRIES 16 32 | #endif 33 | 34 | 35 | 36 | #define DANG_OBJLOG_ENTRIES_ALWAYS 4 37 | #define DANG_STATICLOG_ENTRIES (DANG_OBJLOG_ENTRIES - DANG_OBJLOG_ENTRIES_ALWAYS) 38 | 39 | typedef struct dang_objlog dang_objlog_t; /* Log buffer per-thread and per-object */ 40 | struct dang_objlog { 41 | unsigned long thread_id; /* Per-thread ID */ 42 | dang_objlog_t *next_log; /* Next thread log for the object */ 43 | unsigned long count; /* Number of entries used in log/hash table */ 44 | unsigned long size; /* Hash table size */ 45 | union { 46 | unsigned long *staticlog[DANG_STATICLOG_ENTRIES]; 47 | unsigned long **hashtable; 48 | }; 49 | }; 50 | 51 | #endif /* !DANG_SAN_H */ 52 | -------------------------------------------------------------------------------- /staticlib/Dangling/dang_san_cpp.c: -------------------------------------------------------------------------------- 1 | typedef char bool; 2 | 3 | #define false 0 4 | #define true 1 5 | 6 | extern __thread bool malloc_flag; 7 | extern __thread bool free_flag; 8 | 9 | void *_Znam(unsigned long arg); 10 | void *_Znwm(unsigned long arg); 11 | 12 | void *PointerTrackerUninstrumented__Znam(unsigned long arg) { 13 | void *ptr; 14 | malloc_flag = true; 15 | ptr = _Znam(arg); 16 | malloc_flag = false; 17 | return ptr; 18 | } 19 | 20 | void *PointerTrackerUninstrumented__Znwm(unsigned long arg) { 21 | void *ptr; 22 | malloc_flag = true; 23 | ptr = _Znwm(arg); 24 | malloc_flag = false; 25 | return ptr; 26 | } 27 | -------------------------------------------------------------------------------- /staticlib/Dangling/dsan_atomics.h: -------------------------------------------------------------------------------- 1 | #ifndef DSAN_ATOMICS_H 2 | #define DSAN_ATOMICS_H 3 | 4 | #include 5 | 6 | /* Consistently add value into the addr. 7 | * TODO: Using sequential consistent memory model(strict). We 8 | * will go for the relaxed one if required. 9 | */ 10 | static inline __attribute__((always_inline)) 11 | unsigned long dang_atomic_add(unsigned long *addr, int val) 12 | { 13 | unsigned long expected, desired; 14 | //expected = __atomic_load_8(addr, __ATOMIC_SEQ_CST); 15 | expected = atomic_load((_Atomic(unsigned long)*)addr); 16 | do { 17 | desired = expected + val; 18 | //} while (!__atomic_compare_exchange_8(addr, &expected, desired, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)); 19 | } while (!atomic_compare_exchange_strong((_Atomic(unsigned long)*)addr, &expected, desired)); 20 | return desired; 21 | } 22 | 23 | /* 24 | * Consistently, write desired value into the addr. 25 | * Return old value of addr. Using strict sequential consistency. 26 | */ 27 | static inline __attribute__((always_inline)) 28 | unsigned long dang_atomic_cmpxchng(unsigned long *addr, unsigned long desired) 29 | { 30 | unsigned long expected; 31 | do { 32 | //expected = __atomic_load_8(addr, __ATOMIC_SEQ_CST); 33 | expected = atomic_load((_Atomic(unsigned long)*)addr); 34 | //} while (!__atomic_compare_exchange_8(addr, &expected, desired, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)); 35 | } while (!atomic_compare_exchange_strong((_Atomic(unsigned long)*)addr, &expected, desired)); 36 | 37 | return expected; 38 | } 39 | 40 | static inline __attribute__((always_inline)) 41 | void dang_atomic_cmpxchng_once(unsigned long *addr, unsigned long expected, unsigned long desired) 42 | { 43 | atomic_compare_exchange_strong((_Atomic(unsigned long)*)addr, &expected, desired); 44 | return; 45 | } 46 | 47 | #endif /* !DSAN_ATOMICS_H */ 48 | -------------------------------------------------------------------------------- /staticlib/Dangling/dsan_common.h: -------------------------------------------------------------------------------- 1 | #ifndef DSAN_COMMON_H 2 | #define DSAN_COMMON_H 3 | 4 | #include "metapagetable.h" 5 | #include 6 | #include 7 | 8 | extern __thread bool malloc_flag; 9 | extern __thread bool free_flag; 10 | #define DANG_MALLOC(ptr, type, size) \ 11 | malloc_flag = true; \ 12 | ptr = (type) malloc(size) 13 | #define DANG_FREE(ptr) \ 14 | free_flag = true, free(ptr) 15 | 16 | #define DANG_NULL (unsigned long)0x8000000000000000 17 | 18 | extern void dang_freeptr(unsigned long obj_adr, unsigned long size); 19 | extern void dang_init_heapobj(unsigned long obj_addr, unsigned long size); 20 | 21 | /* 22 | * Initialize function to allocatee mempool, hashtable or any other memory requirement. 23 | */ 24 | void dang_initialize(void) { 25 | 26 | /* Set malloc post hook */ 27 | metalloc_malloc_posthook = dang_init_heapobj; 28 | 29 | /* Set free pre hook */ 30 | metalloc_free_prehook = dang_freeptr; 31 | } 32 | 33 | #endif /* !DSAN_COMMON_H */ 34 | -------------------------------------------------------------------------------- /staticlib/Dangling/dsan_stats_fields.h: -------------------------------------------------------------------------------- 1 | #define FIELD_MEM(name) \ 2 | FIELD_ULONG(mem_##name##_alloc_count); \ 3 | FIELD_ULONG(mem_##name##_alloc_size); \ 4 | FIELD_ULONG(mem_##name##_free_count); \ 5 | FIELD_ULONG(mem_##name##_free_size); \ 6 | FIELD_ULONG(mem_##name##_max_count); \ 7 | FIELD_ULONG(mem_##name##_max_size); 8 | 9 | FIELD_BINS(bins_count); 10 | FIELD_BINS(bins_count_free); 11 | FIELD_BINS(bins_objsize); 12 | FIELD_ULONG(hashtable_alloc); 13 | FIELD_ULONG(hashtable_collision); 14 | FIELD_ULONG(hashtable_dup); 15 | FIELD_ULONG(hashtable_new); 16 | FIELD_ULONG(hashtable_realloc); 17 | FIELD_ULONG(hashtable_register); 18 | FIELD_MEM(threadlog); 19 | FIELD_MEM(hashtable); 20 | FIELD_ULONG(nullify_done); 21 | FIELD_ULONG(nullify_stale); 22 | FIELD_ULONG(object_badptr); 23 | FIELD_ULONG(object_global); 24 | FIELD_ULONG(object_nolog); 25 | FIELD_ULONG(object_stack); 26 | FIELD_ULONG(operation_free); 27 | FIELD_ULONG(operation_malloc); 28 | FIELD_ULONG(operation_register); 29 | FIELD_ULONG(pointer_global); 30 | FIELD_ULONG(pointer_stack); 31 | FIELD_ULONG(segfaults); 32 | FIELD_ULONG(staticlog_add_partial1); 33 | FIELD_ULONG(staticlog_add_partial2); 34 | FIELD_ULONG(staticlog_add_partial3); 35 | 36 | FIELD_ARRAY(staticlog_lookback, DANG_STATICLOG_LOOKBACK + 1); 37 | FIELD_ARRAY(staticlog_lookbackpartial, DANG_STATICLOG_LOOKBACK + 1); 38 | FIELD_ULONG(staticlog_match_badpartial1); 39 | FIELD_ULONG(staticlog_match_badpartial2); 40 | FIELD_ULONG(staticlog_match_badpartial3); 41 | FIELD_ULONG(staticlog_match_badprefix); 42 | FIELD_ULONG(staticlog_match_partial1); 43 | FIELD_ULONG(staticlog_match_partial2); 44 | FIELD_ULONG(staticlog_match_partial3); 45 | FIELD_ULONG(threadlogs); 46 | FIELD_ULONG(threadlogs_next); 47 | -------------------------------------------------------------------------------- /staticlib/Makefile: -------------------------------------------------------------------------------- 1 | CC=clang 2 | METAPAGETABLEDIR=../metapagetable 3 | INCLUDES=-I. -I$(METAPAGETABLEDIR) 4 | CFLAGS=-c -Werror -Wall -flto -fPIC -std=gnu11 5 | OBJDIR=./obj 6 | 7 | CFLAGS += -O3 8 | 9 | EXE=$(OBJDIR)/libmetadata.a 10 | 11 | SRCS := $(wildcard *.c) $(wildcard **/*.c) 12 | OBJS := $(patsubst %.c,$(OBJDIR)/%.o,$(SRCS)) 13 | DEPS := $(OBJS:.o=.d) 14 | 15 | # DangSan configuration 16 | CFLAGS += -DTRACK_ALL_PTRS 17 | CFLAGS += -DNDEBUG 18 | ifdef DANG_STATS 19 | CFLAGS += -DDANG_STATS 20 | endif 21 | ifdef DANG_HASHTABLE_INITSIZE 22 | CFLAGS += -DDANG_HASHTABLE_INITSIZE=${DANG_HASHTABLE_INITSIZE} 23 | endif 24 | ifdef DANG_HASHTABLE_GROWFACTOR 25 | CFLAGS += -DDANG_HASHTABLE_GROWFACTOR=${DANG_HASHTABLE_GROWFACTOR} 26 | endif 27 | ifdef DANG_HASHTABLE_MAXLOADFRAC 28 | CFLAGS += -DDANG_HASHTABLE_MAXLOADFRAC=${DANG_HASHTABLE_MAXLOADFRAC} 29 | endif 30 | ifdef DANG_HASHTABLE_SKIP 31 | CFLAGS += -DDANG_HASHTABLE_SKIP=${DANG_HASHTABLE_SKIP} 32 | endif 33 | ifdef DANG_STATICLOG_LOOKBACK 34 | CFLAGS += -DDANG_STATICLOG_LOOKBACK=${DANG_STATICLOG_LOOKBACK} 35 | endif 36 | ifdef DANG_OBJLOG_ENTRIES 37 | CFLAGS += -DDANG_OBJLOG_ENTRIES=${DANG_OBJLOG_ENTRIES} 38 | endif 39 | 40 | all: directories $(EXE) $(EXE2) 41 | 42 | clean: 43 | rm -f $(OBJS) 44 | rm -f $(DEPS) 45 | rm -f $(EXE) 46 | 47 | $(EXE): $(OBJS) directories 48 | llvm-ar crv $@ $(OBJS) 49 | llvm-ranlib $@ 50 | 51 | -include $(DEPS) 52 | 53 | $(OBJDIR)/%.o: %.c directories 54 | $(CC) $(INCLUDES) $(CFLAGS) -MMD -o $@ $< 55 | 56 | directories: 57 | mkdir -p $(OBJDIR) 58 | mkdir -p $(OBJDIR)/Dangling 59 | -------------------------------------------------------------------------------- /staticlib/compat.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | __attribute__((weak)) size_t strlcpy(char *dst, const char *src, size_t size) { 4 | size_t srclen = strlen(src); 5 | size_t cpylen = (srclen < size) ? srclen : (size - 1); 6 | 7 | memcpy(dst, src, cpylen); 8 | dst[cpylen] = 0; 9 | 10 | return srclen; 11 | } 12 | 13 | __attribute__((weak)) size_t strlcat(char *dst, const char *src, size_t size) { 14 | size_t dstlen = strlen(dst); 15 | size_t srclen = strlen(src); 16 | size_t cpylen; 17 | 18 | if (dstlen < size) { 19 | cpylen = size - dstlen; 20 | if (cpylen > srclen) cpylen = srclen; 21 | memcpy(dst + dstlen, src, cpylen); 22 | dst[cpylen] = 0; 23 | } 24 | 25 | return dstlen + srclen; 26 | } 27 | -------------------------------------------------------------------------------- /staticlib/globalinit.c: -------------------------------------------------------------------------------- 1 | #define _GNU_SOURCE 2 | #define __USE_GNU 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "metadata_init.h" 13 | 14 | /* DangSan: */ 15 | extern void dang_initialize(); 16 | unsigned long dang_global_start; 17 | unsigned long dang_global_size; 18 | 19 | __attribute__ ((visibility("hidden"))) extern char _end; 20 | 21 | __attribute__((visibility ("hidden"), constructor(-1))) void initialize_global_metadata() { 22 | static int initialized; 23 | 24 | /* use both constructor and preinit_array to be first in executables and still work in shared objects */ 25 | if (initialized) return; 26 | initialized = 1; 27 | 28 | if (!is_fixed_compression()) { 29 | /* code, data, bss, ... all assumed to be together */ 30 | Dl_info info = {}; 31 | if (!dladdr(initialize_global_metadata, &info)) { 32 | perror("initialize_global_metadata: dladdr failed"); 33 | exit(-1); 34 | } 35 | char *global_start = info.dli_fbase; 36 | char *global_end = &_end; 37 | initialize_metadata(global_start, global_end); 38 | 39 | /* DangSan: 40 | * Global start and end is required to find global objects/ptrs. 41 | */ 42 | dang_global_start = (unsigned long) global_start; 43 | dang_global_size = (unsigned long) (global_end - global_start); 44 | 45 | /* stack metadata should not be used as objects are supposed to be moved 46 | * to an alternative stack, but we need to be prepared for callbacks 47 | * from JIT code and uninstrumened libraries 48 | */ 49 | struct rlimit rlim; 50 | if (getrlimit(RLIMIT_STACK, &rlim) != 0 || rlim.rlim_cur <= 0 || 51 | rlim.rlim_cur >= 0x80000000) { 52 | rlim.rlim_cur = 0x100000; /* 1MB if no limit set */ 53 | } 54 | char *stack_end; 55 | __asm__("mov %%rsp, %0" : "=R" (stack_end)); 56 | char *stack_start = stack_end - rlim.rlim_cur; 57 | initialize_metadata(stack_start, stack_end); 58 | } 59 | 60 | /* Comment is valid for Dangling pointer design 1. 61 | * FIXME: All metadata for global variables are allocated and initialized just after this function 62 | * call(GlobalTracker.cpp in llvm plugins). 63 | * And, we need to call dang_init_object() for each such allocation. 64 | * However, dang_init_object() requires spinlock and it should be initialized in .preinit_array 65 | * But, order of execution of .preinit_array cannot be specified (TODO: find it) 66 | */ 67 | dang_initialize(); 68 | return; 69 | } 70 | 71 | __attribute__((section(".preinit_array"), 72 | used)) void (*initialize_global_metadat_preinit)(void) = initialize_global_metadata; 73 | -------------------------------------------------------------------------------- /staticlib/metadata_init.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | static void initialize_metadata(char *start, char *end) { 7 | if (start > end) { 8 | fprintf(stderr, "initialize_metadata: bad address range %p-%p\n", start, end); 9 | exit(-1); 10 | } 11 | 12 | unsigned long page_align_offset = METALLOC_PAGESIZE - 1; 13 | unsigned long page_align_mask = ~((unsigned long)METALLOC_PAGESIZE - 1); 14 | char *aligned_start = (void*)((unsigned long)start & page_align_mask); 15 | unsigned long aligned_size = ((end - aligned_start) + page_align_offset) & page_align_mask; 16 | void *metadata = allocate_metadata(aligned_size, GLOBALALIGN); 17 | set_metapagetable_entries(aligned_start, aligned_size, metadata, GLOBALALIGN); 18 | } 19 | 20 | -------------------------------------------------------------------------------- /staticlib/stackinit.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | /* DangSan: */ 9 | __thread unsigned long dang_stack_start; 10 | __thread unsigned long dang_stack_size; 11 | 12 | void unsafe_stack_alloc_meta(void *addr, unsigned long size, bool islarge) { 13 | /* DangSan */ 14 | dang_stack_start = (unsigned long) addr; 15 | dang_stack_size = size; 16 | 17 | if (!is_fixed_compression()) { 18 | unsigned long alignment = STACKALIGN; 19 | if (islarge) 20 | alignment = STACKALIGN_LARGE; 21 | void *metadata = allocate_metadata(size, alignment); 22 | set_metapagetable_entries(addr, size, metadata, alignment); 23 | } 24 | } 25 | 26 | void unsafe_stack_free_meta(void *unsafe_stack_start, unsigned long unsafe_stack_size, bool islarge) { 27 | if (!is_fixed_compression()) { 28 | unsigned long alignment = STACKALIGN; 29 | if (islarge) 30 | alignment = STACKALIGN_LARGE; 31 | deallocate_metadata(unsafe_stack_start, unsafe_stack_size, alignment); 32 | } 33 | } 34 | --------------------------------------------------------------------------------