├── .gitignore ├── .gitmodules ├── .travis.yml ├── Godeps ├── Godeps.json └── Readme ├── MIT-LICENSE.txt ├── Makefile ├── README.md ├── cmd ├── decode.go ├── dump.go ├── flags.go ├── flags_test.go ├── iolibs.go ├── libs.go ├── restore.go └── sync.go ├── pkg ├── libs │ └── pipe │ │ ├── buffer.go │ │ ├── buffer_test.go │ │ ├── file.go │ │ ├── io.go │ │ ├── mem.go │ │ ├── offset.go │ │ ├── pipe.go │ │ └── pipe_test.go └── rdb │ ├── .clang-format │ ├── cgo_3rd_redis0.c │ ├── cgo_3rd_redis1.c │ ├── cgo_3rd_redis2.c │ ├── cgo_glue_debug.c │ ├── cgo_glue_debug.go │ ├── cgo_glue_meow.c │ ├── cgo_glue_server.c │ ├── cgo_iterator.c │ ├── cgo_lazyfree.c │ ├── cgo_load_zset.c │ ├── cgo_objects.c │ ├── cgo_redis.c │ ├── cgo_redis.go │ ├── cgo_redis.h │ ├── cgo_redis_test.go │ ├── loader.go │ ├── loader_simple_test.go │ ├── loader_test.go │ └── testing │ ├── .gitignore │ ├── easily_compressible_string_key.rdb │ ├── empty_database.rdb │ ├── empty_database_nochecksum.rdb │ ├── hash_as_ziplist.rdb │ ├── hash_table.rdb │ ├── integer_keys.rdb │ ├── intset_16.rdb │ ├── intset_32.rdb │ ├── intset_64.rdb │ ├── keys_with_expiry.rdb │ ├── linkedlist.rdb │ ├── list_decode.rdb │ ├── multiple_databases.rdb │ ├── non_ascii_values.rdb │ ├── rdb_version_5_with_checksum.rdb │ ├── rdb_version_8_with_64b_length_and_scores.rdb │ ├── regular_set.rdb │ ├── regular_sorted_set.rdb │ ├── sorted_set_as_ziplist.rdb │ ├── uncompressible_string_keys.rdb │ ├── ziplist_that_compresses_easily.rdb │ ├── ziplist_that_doesnt_compress.rdb │ ├── ziplist_with_integers.rdb │ ├── zipmap_that_compresses_easily.rdb │ ├── zipmap_that_doesnt_compress.rdb │ └── zipmap_with_big_values.rdb ├── vendor └── github.com │ ├── CodisLabs │ └── codis │ │ └── pkg │ │ ├── proxy │ │ └── redis │ │ │ ├── conn.go │ │ │ ├── decoder.go │ │ │ ├── encoder.go │ │ │ └── resp.go │ │ └── utils │ │ ├── assert │ │ └── assert.go │ │ ├── bufio2 │ │ ├── bufio.go │ │ └── slice.go │ │ ├── bytesize │ │ └── bytesize.go │ │ ├── errors │ │ └── errors.go │ │ ├── log │ │ ├── log.go │ │ └── rolling.go │ │ ├── sync2 │ │ └── atomic2 │ │ │ ├── atomic64.go │ │ │ └── bool.go │ │ ├── trace │ │ └── trace.go │ │ └── unsafe2 │ │ ├── cgo_malloc.go │ │ ├── cgo_slice.go │ │ ├── go_slice.go │ │ ├── je_malloc.go │ │ ├── slice.go │ │ └── string.go │ ├── docopt │ └── docopt-go │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── LICENSE │ │ ├── README.md │ │ ├── docopt.go │ │ ├── test_golang.docopt │ │ └── testcases.docopt │ ├── garyburd │ └── redigo │ │ ├── LICENSE │ │ ├── internal │ │ └── commandinfo.go │ │ └── redis │ │ ├── conn.go │ │ ├── doc.go │ │ ├── go17.go │ │ ├── log.go │ │ ├── pool.go │ │ ├── pre_go17.go │ │ ├── pubsub.go │ │ ├── redis.go │ │ ├── reply.go │ │ ├── scan.go │ │ └── script.go │ └── spinlock │ └── jemalloc-go │ ├── .gitignore │ ├── .travis.yml │ ├── Makefile │ ├── README.md │ ├── VERSION │ ├── _config.yml │ ├── help.mk │ ├── je_arena.c │ ├── je_atomic.c │ ├── je_base.c │ ├── je_bitmap.c │ ├── je_chunk.c │ ├── je_chunk_dss.c │ ├── je_chunk_mmap.c │ ├── je_ckh.c │ ├── je_ctl.c │ ├── je_extent.c │ ├── je_hash.c │ ├── je_huge.c │ ├── je_jemalloc.c │ ├── je_mb.c │ ├── je_mutex.c │ ├── je_nstime.c │ ├── je_pages.c │ ├── je_prng.c │ ├── je_prof.c │ ├── je_quarantine.c │ ├── je_rtree.c │ ├── je_spin.c │ ├── je_stats.c │ ├── je_tcache.c │ ├── je_ticker.c │ ├── je_tsd.c │ ├── je_util.c │ ├── je_valgrind.c │ ├── je_witness.c │ ├── jemalloc │ ├── jemalloc-4.5.0 │ ├── .appveyor.yml │ ├── .autom4te.cfg │ ├── .gitattributes │ ├── .gitignore │ ├── .travis.yml │ ├── COPYING │ ├── ChangeLog │ ├── INSTALL │ ├── Makefile.in │ ├── README │ ├── autogen.sh │ ├── bin │ │ ├── jemalloc-config.in │ │ ├── jemalloc.sh.in │ │ └── jeprof.in │ ├── build-aux │ │ ├── config.guess │ │ ├── config.sub │ │ └── install-sh │ ├── config.stamp.in │ ├── configure.ac │ ├── coverage.sh │ ├── doc │ │ ├── html.xsl.in │ │ ├── jemalloc.xml.in │ │ ├── manpages.xsl.in │ │ └── stylesheet.xsl │ ├── include │ │ ├── jemalloc │ │ │ ├── internal │ │ │ │ ├── arena.h │ │ │ │ ├── assert.h │ │ │ │ ├── atomic.h │ │ │ │ ├── base.h │ │ │ │ ├── bitmap.h │ │ │ │ ├── chunk.h │ │ │ │ ├── chunk_dss.h │ │ │ │ ├── chunk_mmap.h │ │ │ │ ├── ckh.h │ │ │ │ ├── ctl.h │ │ │ │ ├── extent.h │ │ │ │ ├── hash.h │ │ │ │ ├── huge.h │ │ │ │ ├── jemalloc_internal.h.in │ │ │ │ ├── jemalloc_internal_decls.h │ │ │ │ ├── jemalloc_internal_defs.h.in │ │ │ │ ├── jemalloc_internal_macros.h │ │ │ │ ├── mb.h │ │ │ │ ├── mutex.h │ │ │ │ ├── nstime.h │ │ │ │ ├── pages.h │ │ │ │ ├── ph.h │ │ │ │ ├── private_namespace.sh │ │ │ │ ├── private_symbols.txt │ │ │ │ ├── private_unnamespace.sh │ │ │ │ ├── prng.h │ │ │ │ ├── prof.h │ │ │ │ ├── public_namespace.sh │ │ │ │ ├── public_unnamespace.sh │ │ │ │ ├── ql.h │ │ │ │ ├── qr.h │ │ │ │ ├── quarantine.h │ │ │ │ ├── rb.h │ │ │ │ ├── rtree.h │ │ │ │ ├── size_classes.sh │ │ │ │ ├── smoothstep.h │ │ │ │ ├── smoothstep.sh │ │ │ │ ├── spin.h │ │ │ │ ├── stats.h │ │ │ │ ├── tcache.h │ │ │ │ ├── ticker.h │ │ │ │ ├── tsd.h │ │ │ │ ├── util.h │ │ │ │ ├── valgrind.h │ │ │ │ └── witness.h │ │ │ ├── jemalloc.sh │ │ │ ├── jemalloc_defs.h.in │ │ │ ├── jemalloc_macros.h.in │ │ │ ├── jemalloc_mangle.sh │ │ │ ├── jemalloc_protos.h.in │ │ │ ├── jemalloc_rename.sh │ │ │ └── jemalloc_typedefs.h.in │ │ └── msvc_compat │ │ │ ├── C99 │ │ │ ├── stdbool.h │ │ │ └── stdint.h │ │ │ ├── strings.h │ │ │ └── windows_extra.h │ ├── jemalloc.pc.in │ ├── msvc │ │ ├── ReadMe.txt │ │ ├── jemalloc_vc2015.sln │ │ └── projects │ │ │ └── vc2015 │ │ │ ├── jemalloc │ │ │ ├── jemalloc.vcxproj │ │ │ └── jemalloc.vcxproj.filters │ │ │ └── test_threads │ │ │ ├── test_threads.cpp │ │ │ ├── test_threads.h │ │ │ ├── test_threads.vcxproj │ │ │ ├── test_threads.vcxproj.filters │ │ │ └── test_threads_main.cpp │ ├── scripts │ │ └── gen_travis.py │ ├── src │ │ ├── arena.c │ │ ├── atomic.c │ │ ├── base.c │ │ ├── bitmap.c │ │ ├── chunk.c │ │ ├── chunk_dss.c │ │ ├── chunk_mmap.c │ │ ├── ckh.c │ │ ├── ctl.c │ │ ├── extent.c │ │ ├── hash.c │ │ ├── huge.c │ │ ├── jemalloc.c │ │ ├── mb.c │ │ ├── mutex.c │ │ ├── nstime.c │ │ ├── pages.c │ │ ├── prng.c │ │ ├── prof.c │ │ ├── quarantine.c │ │ ├── rtree.c │ │ ├── spin.c │ │ ├── stats.c │ │ ├── tcache.c │ │ ├── ticker.c │ │ ├── tsd.c │ │ ├── util.c │ │ ├── valgrind.c │ │ ├── witness.c │ │ └── zone.c │ └── test │ │ ├── include │ │ └── test │ │ │ ├── SFMT-alti.h │ │ │ ├── SFMT-params.h │ │ │ ├── SFMT-params11213.h │ │ │ ├── SFMT-params1279.h │ │ │ ├── SFMT-params132049.h │ │ │ ├── SFMT-params19937.h │ │ │ ├── SFMT-params216091.h │ │ │ ├── SFMT-params2281.h │ │ │ ├── SFMT-params4253.h │ │ │ ├── SFMT-params44497.h │ │ │ ├── SFMT-params607.h │ │ │ ├── SFMT-params86243.h │ │ │ ├── SFMT-sse2.h │ │ │ ├── SFMT.h │ │ │ ├── btalloc.h │ │ │ ├── jemalloc_test.h.in │ │ │ ├── jemalloc_test_defs.h.in │ │ │ ├── math.h │ │ │ ├── mq.h │ │ │ ├── mtx.h │ │ │ ├── test.h │ │ │ ├── thd.h │ │ │ └── timer.h │ │ ├── integration │ │ ├── MALLOCX_ARENA.c │ │ ├── aligned_alloc.c │ │ ├── allocated.c │ │ ├── chunk.c │ │ ├── chunk.sh │ │ ├── mallocx.c │ │ ├── mallocx.sh │ │ ├── overflow.c │ │ ├── posix_memalign.c │ │ ├── rallocx.c │ │ ├── sdallocx.c │ │ ├── thread_arena.c │ │ ├── thread_tcache_enabled.c │ │ ├── xallocx.c │ │ └── xallocx.sh │ │ ├── src │ │ ├── SFMT.c │ │ ├── btalloc.c │ │ ├── btalloc_0.c │ │ ├── btalloc_1.c │ │ ├── math.c │ │ ├── mq.c │ │ ├── mtx.c │ │ ├── test.c │ │ ├── thd.c │ │ └── timer.c │ │ ├── stress │ │ └── microbench.c │ │ ├── test.sh.in │ │ └── unit │ │ ├── SFMT.c │ │ ├── a0.c │ │ ├── arena_reset.c │ │ ├── arena_reset.sh │ │ ├── atomic.c │ │ ├── bitmap.c │ │ ├── ckh.c │ │ ├── decay.c │ │ ├── decay.sh │ │ ├── extent_quantize.c │ │ ├── fork.c │ │ ├── hash.c │ │ ├── junk.c │ │ ├── junk.sh │ │ ├── junk_alloc.c │ │ ├── junk_alloc.sh │ │ ├── junk_free.c │ │ ├── junk_free.sh │ │ ├── lg_chunk.c │ │ ├── lg_chunk.sh │ │ ├── mallctl.c │ │ ├── math.c │ │ ├── mq.c │ │ ├── mtx.c │ │ ├── nstime.c │ │ ├── pack.c │ │ ├── pack.sh │ │ ├── pages.c │ │ ├── ph.c │ │ ├── prng.c │ │ ├── prof_accum.c │ │ ├── prof_accum.sh │ │ ├── prof_active.c │ │ ├── prof_active.sh │ │ ├── prof_gdump.c │ │ ├── prof_gdump.sh │ │ ├── prof_idump.c │ │ ├── prof_idump.sh │ │ ├── prof_reset.c │ │ ├── prof_reset.sh │ │ ├── prof_tctx.sh │ │ ├── prof_thread_name.c │ │ ├── prof_thread_name.sh │ │ ├── ql.c │ │ ├── qr.c │ │ ├── quarantine.c │ │ ├── quarantine.sh │ │ ├── rb.c │ │ ├── rtree.c │ │ ├── run_quantize.c │ │ ├── size_classes.c │ │ ├── smoothstep.c │ │ ├── stats.c │ │ ├── stats_print.c │ │ ├── ticker.c │ │ ├── tsd.c │ │ ├── util.c │ │ ├── witness.c │ │ ├── zero.c │ │ └── zero.sh │ ├── jemalloc.go │ └── jemalloc_test.go ├── version └── wandoujia_license.txt /.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | *.rdb 3 | *.swp 4 | *.out 5 | *.aof 6 | *.dump 7 | *.log.* 8 | 9 | .DS_Store 10 | 11 | /Godeps/_workspace 12 | /cmd/version.go 13 | .htaccess 14 | 15 | /bin 16 | 17 | makefile 18 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "third_party/jemalloc"] 2 | path = third_party/jemalloc 3 | url = https://github.com/jemalloc/jemalloc.git 4 | [submodule "third_party/redis"] 5 | path = third_party/redis 6 | url = https://github.com/antirez/redis.git 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | os: 4 | - linux 5 | - osx 6 | 7 | go: 8 | - 1.10.x 9 | - 1.9.x 10 | - 1.8.x 11 | 12 | script: 13 | - make 14 | - make gotest 15 | 16 | before_deploy: 17 | - export DEPLOY_TARGET=redis-port-${TRAVIS_TAG}-go${TRAVIS_GO_VERSION}-${TRAVIS_OS_NAME} 18 | - mv bin ${DEPLOY_TARGET} 19 | - zip -r ${DEPLOY_TARGET}.zip ${DEPLOY_TARGET} && tar -czvf ${DEPLOY_TARGET}.tar.gz ${DEPLOY_TARGET} 20 | 21 | deploy: 22 | provider: releases 23 | overwrite: true 24 | api_key: 25 | secure: lN7Ub0c46tBBaLgo6WxxVZYbcmygNnWxv6bPrLJ1GOgm0cEwwJJfcyRbmjc46IrEiI8jeT7zuoywlKYl0ARdHT1LlXO/eiIGB4FgHBg6TFRVFsDv9BuNNpM8IPbgAqeZjUju0+s5AoG/kWfjV70QyKcima9VMxhCGNZLlzwGvjs= 26 | file: 27 | - ${DEPLOY_TARGET}.zip 28 | - ${DEPLOY_TARGET}.tar.gz 29 | skip_cleanup: true 30 | on: 31 | repo: CodisLabs/redis-port 32 | tags: true 33 | condition: $TRAVIS_GO_VERSION =~ ^1\.(1[0-9]|[8-9])\.[0-9]+$ 34 | -------------------------------------------------------------------------------- /Godeps/Godeps.json: -------------------------------------------------------------------------------- 1 | { 2 | "ImportPath": "github.com/CodisLabs/redis-port", 3 | "GoVersion": "go1.9", 4 | "GodepVersion": "v79", 5 | "Packages": [ 6 | "./..." 7 | ], 8 | "Deps": [ 9 | { 10 | "ImportPath": "github.com/CodisLabs/codis/pkg/proxy/redis", 11 | "Comment": "3.2.1-10-g9fde2809", 12 | "Rev": "9fde2809cca131e3da1a7e0920ea151029301fb4" 13 | }, 14 | { 15 | "ImportPath": "github.com/CodisLabs/codis/pkg/utils/assert", 16 | "Comment": "3.2.1-10-g9fde2809", 17 | "Rev": "9fde2809cca131e3da1a7e0920ea151029301fb4" 18 | }, 19 | { 20 | "ImportPath": "github.com/CodisLabs/codis/pkg/utils/bufio2", 21 | "Comment": "3.2.1-10-g9fde2809", 22 | "Rev": "9fde2809cca131e3da1a7e0920ea151029301fb4" 23 | }, 24 | { 25 | "ImportPath": "github.com/CodisLabs/codis/pkg/utils/bytesize", 26 | "Comment": "3.2.1-10-g9fde2809", 27 | "Rev": "9fde2809cca131e3da1a7e0920ea151029301fb4" 28 | }, 29 | { 30 | "ImportPath": "github.com/CodisLabs/codis/pkg/utils/errors", 31 | "Comment": "3.2.1-10-g9fde2809", 32 | "Rev": "9fde2809cca131e3da1a7e0920ea151029301fb4" 33 | }, 34 | { 35 | "ImportPath": "github.com/CodisLabs/codis/pkg/utils/log", 36 | "Comment": "3.2.1-10-g9fde2809", 37 | "Rev": "9fde2809cca131e3da1a7e0920ea151029301fb4" 38 | }, 39 | { 40 | "ImportPath": "github.com/CodisLabs/codis/pkg/utils/sync2/atomic2", 41 | "Comment": "3.2.1-10-g9fde2809", 42 | "Rev": "9fde2809cca131e3da1a7e0920ea151029301fb4" 43 | }, 44 | { 45 | "ImportPath": "github.com/CodisLabs/codis/pkg/utils/trace", 46 | "Comment": "3.2.1-10-g9fde2809", 47 | "Rev": "9fde2809cca131e3da1a7e0920ea151029301fb4" 48 | }, 49 | { 50 | "ImportPath": "github.com/CodisLabs/codis/pkg/utils/unsafe2", 51 | "Comment": "3.2.1-10-g9fde2809", 52 | "Rev": "9fde2809cca131e3da1a7e0920ea151029301fb4" 53 | }, 54 | { 55 | "ImportPath": "github.com/docopt/docopt-go", 56 | "Comment": "0.6.2", 57 | "Rev": "784ddc588536785e7299f7272f39101f7faccc3f" 58 | }, 59 | { 60 | "ImportPath": "github.com/garyburd/redigo/internal", 61 | "Comment": "v1.0.0-20-g4854517", 62 | "Rev": "48545177e92ae3e7bcdbd50b42f7a139e6a268da" 63 | }, 64 | { 65 | "ImportPath": "github.com/garyburd/redigo/redis", 66 | "Comment": "v1.0.0-20-g4854517", 67 | "Rev": "48545177e92ae3e7bcdbd50b42f7a139e6a268da" 68 | }, 69 | { 70 | "ImportPath": "github.com/spinlock/jemalloc-go", 71 | "Comment": "4.5.0-2-g2e84521", 72 | "Rev": "2e84521acd411768e7b5a9e996d3853b3a53b644" 73 | } 74 | ] 75 | } 76 | -------------------------------------------------------------------------------- /Godeps/Readme: -------------------------------------------------------------------------------- 1 | This directory tree is generated automatically by godep. 2 | 3 | Please do not edit. 4 | 5 | See https://github.com/tools/godep for more information. 6 | -------------------------------------------------------------------------------- /MIT-LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 CodisLabs 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .DEFAULT_GOAL := build-all 2 | 3 | export GO15VENDOREXPERIMENT=1 4 | 5 | UNAME_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') 6 | 7 | GO_BUILD := go build 8 | GO_TEST := go test 9 | 10 | ifeq ($(UNAME_S),Linux) 11 | GO_BUILD += -tags "use_jemalloc" 12 | GO_TEST += -tags "use_jemalloc" 13 | build-deps: build-jemalloc 14 | endif 15 | 16 | ifeq ($(UNAME_S),Darwin) 17 | GO_BUILD += -ldflags="-s" 18 | GO_TEST += -ldflags="-s" 19 | endif 20 | 21 | build-all: redis-sync redis-dump redis-decode redis-restore 22 | 23 | GO_SRCS := $(shell bash -c 'echo cmd/{version,flags,libs,iolibs}.go') 24 | 25 | build-deps: 26 | @mkdir -p bin && bash version 27 | 28 | redis-sync: build-deps 29 | ${GO_BUILD} -o bin/$@ \ 30 | ${GO_SRCS} cmd/sync.go 31 | 32 | redis-dump: build-deps 33 | ${GO_BUILD} -o bin/$@ \ 34 | ${GO_SRCS} cmd/dump.go 35 | 36 | redis-decode: build-deps 37 | ${GO_BUILD} -o bin/$@ \ 38 | ${GO_SRCS} cmd/decode.go 39 | 40 | redis-restore: build-deps 41 | ${GO_BUILD} -o bin/$@ \ 42 | ${GO_SRCS} cmd/restore.go 43 | 44 | clean: 45 | @rm -rf bin 46 | 47 | distclean: clean 48 | @make distclean --no-print-directory --quiet -C third_party/redis 49 | @[ ! -f third_party/jemalloc/Makefile ] || \ 50 | make distclean --no-print-directory --quiet -C third_party/jemalloc 51 | 52 | gotest: build-deps gotest-flags 53 | ${GO_TEST} -v ./pkg/... 54 | 55 | gotest-flags: build-deps 56 | ${GO_TEST} -v ./cmd/version.go ./cmd/flags.go ./cmd/flags_test.go 57 | 58 | jemalloc: 59 | @cd third_party/jemalloc && \ 60 | ./autogen.sh --with-jemalloc-prefix="je_" && make -j 61 | 62 | build-jemalloc: 63 | @[ -f third_party/jemalloc/lib/libjemalloc_pic.a ] || \ 64 | make jemalloc --no-print-directory 65 | -------------------------------------------------------------------------------- /cmd/flags_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "math" 5 | "strings" 6 | "testing" 7 | "time" 8 | 9 | "github.com/CodisLabs/codis/pkg/utils/assert" 10 | ) 11 | 12 | func parseFlagsFromString(line string) *Flags { 13 | var array = []string{} 14 | for _, s := range strings.Split(line, " ") { 15 | if t := strings.TrimSpace(s); t != "" { 16 | array = append(array, t) 17 | } 18 | } 19 | const usage = ` 20 | Usage: 21 | test [--master=MASTER|MASTER] [--target=TARGET] 22 | test [--tmpfile=FILE --tmpfile-size=SIZE] 23 | test [--unixtime-in-milliseconds=EXPR] 24 | test --version 25 | 26 | Options: 27 | -m MASTER, --master=MASTER 28 | -t TARGET, --target=TARGET 29 | ` 30 | return parseFlagsFromArgs(usage, array) 31 | } 32 | 33 | func TestParseFlagsMasterTarget(t *testing.T) { 34 | var testcase = func(line string, source, target string) { 35 | var flags = parseFlagsFromString(line) 36 | assert.Must(flags.Source == source) 37 | assert.Must(flags.Target == target) 38 | } 39 | testcase("", "", "") 40 | testcase("abc", "abc", "") 41 | testcase("-m abc", "abc", "") 42 | testcase("--master abc", "abc", "") 43 | testcase("a/b/c", "a/b/c", "") 44 | testcase("/a/b/c", "/a/b/c", "") 45 | testcase("//a/b/c", "//a/b/c", "") 46 | 47 | testcase("-t abc", "", "abc") 48 | testcase("--target abc", "", "abc") 49 | 50 | testcase("abc -t xyz", "abc", "xyz") 51 | testcase("-m abc -t xyz", "abc", "xyz") 52 | } 53 | 54 | func TestParseFlagsFileSize(t *testing.T) { 55 | var testcase = func(line string, path string, size int64) { 56 | var flags = parseFlagsFromString(line) 57 | assert.Must(flags.TmpFile.Path == path) 58 | assert.Must(flags.TmpFile.Size == size) 59 | } 60 | testcase("", "", 0) 61 | testcase("--tmpfile-size=1gb", "", 1<<30) 62 | testcase("--tmpfile=/a/b/c --tmpfile-size=1gb", "/a/b/c", 1<<30) 63 | } 64 | 65 | func TestParseFlagsUnixtime(t *testing.T) { 66 | var testcase = func(line string, offset, delta time.Duration) { 67 | var flags = parseFlagsFromString(line) 68 | assert.Must(math.Abs(float64(flags.ExpireOffset-offset)) <= math.Abs(float64(delta))) 69 | } 70 | var now = time.Duration(time.Now().UnixNano()) 71 | testcase("", 0, 0) 72 | testcase("--unixtime-in-milliseconds=@0", now, time.Second) 73 | testcase("--unixtime-in-milliseconds=+1000ms", time.Second, 0) 74 | testcase("--unixtime-in-milliseconds=-1000ms", -time.Second, 0) 75 | } 76 | -------------------------------------------------------------------------------- /cmd/iolibs.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "io" 6 | "sync" 7 | 8 | "github.com/CodisLabs/codis/pkg/utils/bufio2" 9 | "github.com/CodisLabs/codis/pkg/utils/log" 10 | "github.com/CodisLabs/codis/pkg/utils/sync2/atomic2" 11 | ) 12 | 13 | type ReaderBuilder struct { 14 | io.Reader 15 | } 16 | 17 | func rBuilder(r io.Reader) *ReaderBuilder { 18 | return &ReaderBuilder{r} 19 | } 20 | 21 | func (b *ReaderBuilder) Must() *ReaderBuilder { 22 | b.Reader = &MustReader{b.Reader} 23 | return b 24 | } 25 | 26 | func (b *ReaderBuilder) Count(p *atomic2.Int64) *ReaderBuilder { 27 | b.Reader = &CountReader{b.Reader, p} 28 | return b 29 | } 30 | 31 | func (b *ReaderBuilder) Limit(n int64) *ReaderBuilder { 32 | b.Reader = io.LimitReader(b.Reader, n) 33 | return b 34 | } 35 | 36 | func (b *ReaderBuilder) Buffer(size int) *ReaderBuilder { 37 | b.Reader = bufio.NewReaderSize(b.Reader, size) 38 | return b 39 | } 40 | 41 | func (b *ReaderBuilder) Buffer2(size int) *ReaderBuilder { 42 | b.Reader = bufio2.NewReaderSize(b.Reader, size) 43 | return b 44 | } 45 | 46 | type MustReader struct { 47 | io.Reader 48 | } 49 | 50 | func (r *MustReader) Read(b []byte) (int, error) { 51 | n, err := r.Reader.Read(b) 52 | if err != nil { 53 | log.PanicErrorf(err, "read bytes failed") 54 | } 55 | return n, nil 56 | } 57 | 58 | type CountReader struct { 59 | io.Reader 60 | N *atomic2.Int64 61 | } 62 | 63 | func (r *CountReader) Read(b []byte) (int, error) { 64 | n, err := r.Reader.Read(b) 65 | r.N.Add(int64(n)) 66 | return n, err 67 | } 68 | 69 | type WriterBuilder struct { 70 | io.Writer 71 | } 72 | 73 | func wBuilder(w io.Writer) *WriterBuilder { 74 | return &WriterBuilder{w} 75 | } 76 | 77 | func (b *WriterBuilder) Must() *WriterBuilder { 78 | b.Writer = &MustWriter{b.Writer} 79 | return b 80 | } 81 | 82 | func (b *WriterBuilder) Count(p *atomic2.Int64) *WriterBuilder { 83 | b.Writer = &CountWriter{b.Writer, p} 84 | return b 85 | } 86 | 87 | func (b *WriterBuilder) Mutex(l sync.Locker) *WriterBuilder { 88 | b.Writer = &MutexWriter{b.Writer, l} 89 | return b 90 | } 91 | 92 | func (b *WriterBuilder) Buffer(size int) *WriterBuilder { 93 | b.Writer = bufio.NewWriterSize(b.Writer, size) 94 | return b 95 | } 96 | 97 | func (b *WriterBuilder) Buffer2(size int) *WriterBuilder { 98 | b.Writer = bufio2.NewWriterSize(b.Writer, size) 99 | return b 100 | } 101 | 102 | type MustWriter struct { 103 | io.Writer 104 | } 105 | 106 | func (w *MustWriter) Write(b []byte) (int, error) { 107 | n, err := w.Writer.Write(b) 108 | if err != nil { 109 | log.PanicErrorf(err, "write bytes failed") 110 | } 111 | return n, nil 112 | } 113 | 114 | type CountWriter struct { 115 | io.Writer 116 | N *atomic2.Int64 117 | } 118 | 119 | func (w *CountWriter) Write(b []byte) (int, error) { 120 | n, err := w.Writer.Write(b) 121 | w.N.Add(int64(n)) 122 | return n, err 123 | } 124 | 125 | type MutexWriter struct { 126 | io.Writer 127 | L sync.Locker 128 | } 129 | 130 | func (w *MutexWriter) Write(b []byte) (int, error) { 131 | w.L.Lock() 132 | n, err := w.Writer.Write(b) 133 | w.L.Unlock() 134 | return n, err 135 | } 136 | -------------------------------------------------------------------------------- /pkg/libs/pipe/buffer.go: -------------------------------------------------------------------------------- 1 | package pipe 2 | 3 | type Buffer interface { 4 | ReadSome(b []byte) (int, error) 5 | Buffered() int 6 | CloseReader() error 7 | 8 | WriteSome(b []byte) (int, error) 9 | Available() int 10 | CloseWriter() error 11 | } 12 | -------------------------------------------------------------------------------- /pkg/libs/pipe/buffer_test.go: -------------------------------------------------------------------------------- 1 | package pipe 2 | 3 | import ( 4 | "io/ioutil" 5 | "math/rand" 6 | "os" 7 | "testing" 8 | 9 | "github.com/CodisLabs/codis/pkg/utils/assert" 10 | ) 11 | 12 | func testBufferReadWriteSome(p Buffer) { 13 | var makeSlice = func(n int) []byte { 14 | return make([]byte, rand.Intn(n)+1) 15 | } 16 | var rpos uint64 17 | var readSome = func() int { 18 | buffered := p.Buffered() 19 | var b = makeSlice(512) 20 | n, err := p.ReadSome(b) 21 | assert.MustNoError(err) 22 | if buffered != 0 { 23 | assert.Must(n != 0) 24 | } else { 25 | assert.Must(n == 0) 26 | } 27 | for i := 0; i < n; i++ { 28 | assert.Must(b[i] == byte(rpos+uint64(i))) 29 | } 30 | rpos += uint64(n) 31 | return n 32 | } 33 | var wpos uint64 34 | var writeSome = func() int { 35 | available := p.Available() 36 | var b = makeSlice(512) 37 | for i := 0; i < len(b); i++ { 38 | b[i] = byte(wpos + uint64(i)) 39 | } 40 | n, err := p.WriteSome(b) 41 | assert.MustNoError(err) 42 | if available != 0 { 43 | assert.Must(n != 0) 44 | } else { 45 | assert.Must(n == 0) 46 | } 47 | wpos += uint64(n) 48 | return n 49 | } 50 | var nread, nwrite int 51 | for nread < 1024*1024*128 { 52 | nread += readSome() 53 | nwrite += writeSome() 54 | } 55 | for nread != nwrite { 56 | nread += readSome() 57 | } 58 | } 59 | 60 | func TestMemBuffer(t *testing.T) { 61 | testBufferReadWriteSome(&memBuffer{buf: make([]byte, 32749)}) 62 | } 63 | 64 | func TestFileBuffer(t *testing.T) { 65 | f, err := ioutil.TempFile("", "pipe_buffer_test_") 66 | assert.MustNoError(err) 67 | defer func() { 68 | assert.MustNoError(f.Close()) 69 | }() 70 | testBufferReadWriteSome(&fileBuffer{file: f, size: 32749}) 71 | assert.MustNoError(os.Remove(f.Name())) 72 | } 73 | -------------------------------------------------------------------------------- /pkg/libs/pipe/file.go: -------------------------------------------------------------------------------- 1 | package pipe 2 | 3 | import ( 4 | "io" 5 | "os" 6 | 7 | "github.com/CodisLabs/codis/pkg/utils/errors" 8 | ) 9 | 10 | const ( 11 | fileBufferPageSize = 1024 * 1024 * 4 12 | defaultFileBufferSize = 1024 * 1024 * 32 13 | ) 14 | 15 | type fileBuffer struct { 16 | file *os.File 17 | size int 18 | rpos uint64 19 | wpos uint64 20 | } 21 | 22 | func newFileBuffer(file *os.File) *fileBuffer { 23 | return newFileBufferSize(file, defaultFileBufferSize) 24 | } 25 | 26 | func newFileBufferSize(file *os.File, size int) *fileBuffer { 27 | if size < defaultFileBufferSize { 28 | size = defaultFileBufferSize 29 | } else { 30 | size = align(size, fileBufferPageSize) 31 | } 32 | return &fileBuffer{file: file, size: size} 33 | } 34 | 35 | func (p *fileBuffer) ReadSome(b []byte) (int, error) { 36 | if p.file == nil { 37 | return 0, errors.Trace(io.ErrClosedPipe) 38 | } 39 | n, offset := roffset(len(b), p.size, p.rpos, p.wpos) 40 | nn, err := p.file.ReadAt(b[:n], int64(offset)) 41 | 42 | p.rpos += uint64(nn) 43 | if p.rpos == p.wpos { 44 | p.rpos = 0 45 | p.wpos = 0 46 | if err == nil { 47 | err = p.file.Truncate(0) 48 | } 49 | } 50 | return nn, errors.Trace(err) 51 | } 52 | 53 | func (p *fileBuffer) Buffered() int { 54 | if p.file == nil { 55 | return 0 56 | } 57 | return int(p.wpos - p.rpos) 58 | } 59 | 60 | func (p *fileBuffer) CloseReader() error { 61 | if f := p.file; f != nil { 62 | p.file = nil 63 | return errors.Trace(f.Truncate(0)) 64 | } 65 | return nil 66 | } 67 | 68 | func (p *fileBuffer) WriteSome(b []byte) (int, error) { 69 | if p.file == nil { 70 | return 0, errors.Trace(io.ErrClosedPipe) 71 | } 72 | n, offset := woffset(len(b), p.size, p.rpos, p.wpos) 73 | nn, err := p.file.WriteAt(b[:n], int64(offset)) 74 | 75 | p.wpos += uint64(nn) 76 | return nn, errors.Trace(err) 77 | } 78 | 79 | func (p *fileBuffer) Available() int { 80 | if p.file == nil { 81 | return 0 82 | } 83 | return p.size - int(p.wpos-p.rpos) 84 | } 85 | 86 | func (p *fileBuffer) CloseWriter() error { 87 | return nil 88 | } 89 | -------------------------------------------------------------------------------- /pkg/libs/pipe/io.go: -------------------------------------------------------------------------------- 1 | package pipe 2 | 3 | import ( 4 | "io" 5 | "os" 6 | ) 7 | 8 | type Reader interface { 9 | io.ReadCloser 10 | Buffered() (int, error) 11 | CloseWithError(err error) error 12 | } 13 | 14 | type Writer interface { 15 | io.WriteCloser 16 | Available() (int, error) 17 | CloseWithError(err error) error 18 | } 19 | 20 | type PipeReader struct { 21 | *Pipe 22 | } 23 | 24 | func (p *PipeReader) Close() error { 25 | return p.CloseReader(nil) 26 | } 27 | 28 | func (p *PipeReader) CloseWithError(err error) error { 29 | return p.CloseReader(err) 30 | } 31 | 32 | type PipeWriter struct { 33 | *Pipe 34 | } 35 | 36 | func (p *PipeWriter) Close() error { 37 | return p.CloseWriter(nil) 38 | } 39 | 40 | func (p *PipeWriter) CloseWithError(err error) error { 41 | return p.CloseWriter(err) 42 | } 43 | 44 | func New() (Reader, Writer) { 45 | return NewSize(defaultMemBufferSize) 46 | } 47 | 48 | func NewSize(size int) (Reader, Writer) { 49 | var p = NewPipeSize(size) 50 | return p.Reader(), p.Writer() 51 | } 52 | 53 | func NewFile(file *os.File, size int) (Reader, Writer) { 54 | var p = NewPipeFile(file, size) 55 | return p.Reader(), p.Writer() 56 | } 57 | -------------------------------------------------------------------------------- /pkg/libs/pipe/mem.go: -------------------------------------------------------------------------------- 1 | package pipe 2 | 3 | import ( 4 | "io" 5 | 6 | "github.com/CodisLabs/codis/pkg/utils/errors" 7 | ) 8 | 9 | const ( 10 | memBufferPageSize = 1024 * 4 11 | defaultMemBufferSize = 1024 * 1024 * 8 12 | ) 13 | 14 | type memBuffer struct { 15 | buf []byte 16 | 17 | rpos uint64 18 | wpos uint64 19 | } 20 | 21 | func newMemBuffer() *memBuffer { 22 | return newMemBufferSize(defaultMemBufferSize) 23 | } 24 | 25 | func newMemBufferSize(size int) *memBuffer { 26 | if size < defaultMemBufferSize { 27 | size = defaultMemBufferSize 28 | } else { 29 | size = align(size, memBufferPageSize) 30 | } 31 | return &memBuffer{buf: make([]byte, size)} 32 | } 33 | 34 | func (p *memBuffer) ReadSome(b []byte) (int, error) { 35 | if len(p.buf) == 0 { 36 | return 0, errors.Trace(io.ErrClosedPipe) 37 | } 38 | n, offset := roffset(len(b), len(p.buf), p.rpos, p.wpos) 39 | copy(b[:n], p.buf[offset:]) 40 | 41 | p.rpos += uint64(n) 42 | if p.rpos == p.wpos { 43 | p.rpos = 0 44 | p.wpos = 0 45 | } 46 | return n, nil 47 | } 48 | 49 | func (p *memBuffer) Buffered() int { 50 | if len(p.buf) == 0 { 51 | return 0 52 | } 53 | return int(p.wpos - p.rpos) 54 | } 55 | 56 | func (p *memBuffer) CloseReader() error { 57 | p.buf = nil 58 | return nil 59 | } 60 | 61 | func (p *memBuffer) WriteSome(b []byte) (int, error) { 62 | if len(p.buf) == 0 { 63 | return 0, errors.Trace(io.ErrClosedPipe) 64 | } 65 | n, offset := woffset(len(b), len(p.buf), p.rpos, p.wpos) 66 | copy(p.buf[offset:], b[:n]) 67 | 68 | p.wpos += uint64(n) 69 | return n, nil 70 | } 71 | 72 | func (p *memBuffer) Available() int { 73 | if len(p.buf) == 0 { 74 | return 0 75 | } 76 | return len(p.buf) - int(p.wpos-p.rpos) 77 | } 78 | 79 | func (p *memBuffer) CloseWriter() error { 80 | return nil 81 | } 82 | -------------------------------------------------------------------------------- /pkg/libs/pipe/offset.go: -------------------------------------------------------------------------------- 1 | package pipe 2 | 3 | func align(n, unit int) int { 4 | if n < unit { 5 | return unit 6 | } 7 | return (n + unit - 1) / unit * unit 8 | } 9 | 10 | func roffset(n, size int, rpos, wpos uint64) (nn int, offset uint64) { 11 | if d := int(wpos - rpos); d < n { 12 | n = d 13 | } 14 | offset = rpos % uint64(size) 15 | if d := size - int(offset); d < n { 16 | n = d 17 | } 18 | return n, offset 19 | } 20 | 21 | func woffset(n, size int, rpos, wpos uint64) (nn int, offset uint64) { 22 | if d := size - int(wpos-rpos); d < n { 23 | n = d 24 | } 25 | offset = wpos % uint64(size) 26 | if d := size - int(offset); d < n { 27 | n = d 28 | } 29 | return n, offset 30 | } 31 | -------------------------------------------------------------------------------- /pkg/rdb/cgo_3rd_redis0.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | -------------------------------------------------------------------------------- /pkg/rdb/cgo_3rd_redis1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | extern long int random(void); 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | -------------------------------------------------------------------------------- /pkg/rdb/cgo_3rd_redis2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | -------------------------------------------------------------------------------- /pkg/rdb/cgo_glue_debug.c: -------------------------------------------------------------------------------- 1 | #include "cgo_redis.h" 2 | 3 | #ifdef LOG_MAX_LEN 4 | #undef LOG_MAX_LEN 5 | #endif 6 | 7 | #define LOG_MAX_LEN (1024 * 512) 8 | 9 | extern void cgoRedisLogPanic(const char *buf, size_t len); 10 | 11 | void _serverAssert(const char *estr, const char *file, int line) { 12 | char buf[LOG_MAX_LEN]; 13 | const char *format = 14 | "===== ASSERTION FAILED =====\n" 15 | "====> %s:%d '%s' is not true\n"; 16 | size_t len = snprintf(buf, sizeof(buf), format, file, line, estr); 17 | 18 | cgoRedisLogPanic(buf, len); 19 | exit(1); 20 | } 21 | 22 | void _serverAssertWithInfo(const client *c, const robj *o, const char *estr, 23 | const char *file, int line) { 24 | _serverAssert(estr, file, line); 25 | } 26 | 27 | void _serverPanic(const char *file, int line, const char *vformat, ...) { 28 | char buf[LOG_MAX_LEN]; 29 | const char *format = 30 | "===== REDIS CGO PANIC ======\n" 31 | "====> %s:%d\n"; 32 | size_t len1 = snprintf(buf, sizeof(buf), format, file, line); 33 | 34 | va_list ap; 35 | va_start(ap, vformat); 36 | size_t len2 = vsnprintf(buf + len1, sizeof(buf) - len1, vformat, ap); 37 | va_end(ap); 38 | 39 | cgoRedisLogPanic(buf, len1 + len2); 40 | exit(1); 41 | } 42 | 43 | extern void cgoRedisLogLevel(const char *buf, size_t len, int level); 44 | 45 | void serverLog(int level, const char *format, ...) { 46 | char buf[LOG_MAX_LEN]; 47 | va_list ap; 48 | va_start(ap, format); 49 | size_t len = vsnprintf(buf, sizeof(buf), format, ap); 50 | va_end(ap); 51 | 52 | cgoRedisLogLevel(buf, len, level); 53 | } 54 | 55 | int rdbCheckMode = 0; 56 | 57 | void rdbCheckError(const char *vformat, ...) { 58 | char buf[LOG_MAX_LEN]; 59 | const char *format = 60 | "===== RDB CHECK ERROR ======\n" 61 | "====> %s:%d\n"; 62 | size_t len1 = snprintf(buf, sizeof(buf), format, __FILE__, __LINE__); 63 | 64 | va_list ap; 65 | va_start(ap, vformat); 66 | size_t len2 = vsnprintf(buf + len1, sizeof(buf) - len1, vformat, ap); 67 | va_end(ap); 68 | 69 | cgoRedisLogPanic(buf, len1 + len2); 70 | exit(1); 71 | } 72 | 73 | void rdbCheckSetError(const char *vformat, ...) { 74 | char buf[LOG_MAX_LEN]; 75 | const char *format = 76 | "===== RDB CHECK ERROR ======\n" 77 | "====> %s:%d\n"; 78 | size_t len1 = snprintf(buf, sizeof(buf), format, __FILE__, __LINE__); 79 | 80 | va_list ap; 81 | va_start(ap, vformat); 82 | size_t len2 = vsnprintf(buf + len1, sizeof(buf) - len1, vformat, ap); 83 | va_end(ap); 84 | 85 | cgoRedisLogPanic(buf, len1 + len2); 86 | exit(1); 87 | } 88 | -------------------------------------------------------------------------------- /pkg/rdb/cgo_glue_debug.go: -------------------------------------------------------------------------------- 1 | package rdb 2 | 3 | import ( 4 | "C" 5 | "unsafe" 6 | 7 | "github.com/CodisLabs/codis/pkg/utils/log" 8 | ) 9 | 10 | //export cgoRedisLogPanic 11 | func cgoRedisLogPanic(buf unsafe.Pointer, len C.size_t) { 12 | log.Panicf("In Redis CGo:\n%s", unsafeCastToSlice(buf, len)) 13 | } 14 | 15 | //export cgoRedisLogLevel 16 | func cgoRedisLogLevel(buf unsafe.Pointer, len C.size_t, level C.int) { 17 | func() func(format string, args ...interface{}) { 18 | switch level { 19 | case 0: 20 | return log.Debugf 21 | case 3: 22 | return log.Warnf 23 | default: 24 | return log.Infof 25 | } 26 | }()("In Redis CGo: %s", unsafeCastToSlice(buf, len)) 27 | } 28 | -------------------------------------------------------------------------------- /pkg/rdb/cgo_lazyfree.c: -------------------------------------------------------------------------------- 1 | #include "cgo_redis.h" 2 | 3 | #define LAZYFREE_NUM_THREADS 8 4 | 5 | typedef struct { 6 | pthread_t threads[LAZYFREE_NUM_THREADS]; 7 | pthread_mutex_t mutex; 8 | pthread_cond_t cond; 9 | list *objs; 10 | } lazyfreeThreads; 11 | 12 | static void *lazyfreeThreadMain(void *args) { 13 | lazyfreeThreads *p = args; 14 | while (1) { 15 | pthread_mutex_lock(&p->mutex); 16 | while (listLength(p->objs) == 0) { 17 | pthread_cond_wait(&p->cond, &p->mutex); 18 | } 19 | listNode *head = listFirst(p->objs); 20 | robj *o = listNodeValue(head); 21 | listDelNode(p->objs, head); 22 | pthread_mutex_unlock(&p->mutex); 23 | serverAssert(o->refcount == 1); 24 | decrRefCount(o); 25 | } 26 | return NULL; 27 | } 28 | 29 | static lazyfreeThreads *createLazyfreeThreads(void) { 30 | lazyfreeThreads *p = zmalloc(sizeof(*p)); 31 | pthread_mutex_init(&p->mutex, NULL); 32 | pthread_cond_init(&p->cond, NULL); 33 | p->objs = listCreate(); 34 | for (int i = 0; i < LAZYFREE_NUM_THREADS; i++) { 35 | int ret = pthread_create(&p->threads[i], NULL, lazyfreeThreadMain, p); 36 | if (ret != 0) { 37 | serverPanic("Can't create Lazyfree Threads-[%d] [%d].", i, ret); 38 | } 39 | } 40 | return p; 41 | } 42 | 43 | static lazyfreeThreads *lazyfree_threads = NULL; 44 | 45 | void initLazyfreeThreads() { lazyfree_threads = createLazyfreeThreads(); } 46 | 47 | void decrRefCountByLazyfreeThreads(robj *o) { 48 | serverAssert(o->refcount == 1 && lazyfree_threads != NULL); 49 | lazyfreeThreads *p = lazyfree_threads; 50 | pthread_mutex_lock(&p->mutex); 51 | if (listLength(p->objs) == 0) { 52 | pthread_cond_signal(&p->cond); 53 | } 54 | listAddNodeTail(p->objs, o); 55 | pthread_mutex_unlock(&p->mutex); 56 | } 57 | 58 | size_t lazyfreeObjectGetFreeEffort(robj *o) { 59 | if (o->refcount == 1 && lazyfree_threads != NULL) { 60 | switch (o->type) { 61 | case OBJ_LIST: 62 | if (o->encoding == OBJ_ENCODING_QUICKLIST) { 63 | return listTypeLength(o); 64 | } 65 | return 0; 66 | case OBJ_HASH: 67 | if (o->encoding == OBJ_ENCODING_HT) { 68 | return hashTypeLength(o) * 2; 69 | } 70 | return 0; 71 | case OBJ_SET: 72 | if (o->encoding == OBJ_ENCODING_HT) { 73 | return setTypeSize(o); 74 | } 75 | return 0; 76 | case OBJ_ZSET: 77 | if (o->encoding == OBJ_ENCODING_SKIPLIST) { 78 | return zsetLength(o) * 2; 79 | } 80 | return 0; 81 | } 82 | } 83 | return 0; 84 | } 85 | -------------------------------------------------------------------------------- /pkg/rdb/cgo_objects.c: -------------------------------------------------------------------------------- 1 | #include "cgo_redis.h" 2 | 3 | int redisObjectType(void *obj) { return ((robj *)obj)->type; } 4 | int redisObjectEncoding(void *obj) { return ((robj *)obj)->encoding; } 5 | int redisObjectRefCount(void *obj) { return ((robj *)obj)->refcount; } 6 | 7 | extern size_t lazyfreeObjectGetFreeEffort(robj *o); 8 | extern void decrRefCountByLazyfreeThreads(robj *o); 9 | 10 | void redisObjectIncrRefCount(void *obj) { incrRefCount(obj); } 11 | 12 | void redisObjectDecrRefCount(void *obj, int lazyfree) { 13 | if (!lazyfree || lazyfreeObjectGetFreeEffort((robj *)obj) < 128) { 14 | decrRefCount(obj); 15 | } else { 16 | decrRefCountByLazyfreeThreads((robj *)obj); 17 | } 18 | } 19 | 20 | extern void createDumpPayload(rio *payload, robj *o); 21 | 22 | void redisObjectCreateDumpPayload(void *obj, redisSds *p) { 23 | rio payload; 24 | createDumpPayload(&payload, obj); 25 | p->ptr = payload.io.buffer.ptr; 26 | p->len = sdslen(p->ptr); 27 | } 28 | 29 | extern int verifyDumpPayload(const char *buf, size_t len); 30 | 31 | void *redisObjectDecodeFromPayload(void *buf, size_t len) { 32 | rio payload; 33 | if (verifyDumpPayload(buf, len) != C_OK) { 34 | return NULL; 35 | } 36 | int type; 37 | robj *obj = NULL; 38 | sds iobuf = sdsnewlen(buf, len); 39 | rioInitWithBuffer(&payload, iobuf); 40 | if ((type = rdbLoadObjectType(&payload)) != -1) { 41 | obj = rdbLoadObject(type, &payload); 42 | } 43 | sdsfree(iobuf); 44 | return obj; 45 | } 46 | 47 | size_t redisStringObjectLen(void *obj) { 48 | robj *o = obj; 49 | serverAssert(o->type == OBJ_STRING); 50 | return stringObjectLen(o); 51 | } 52 | 53 | void redisStringObjectLoad(void *obj, redisSds *p) { 54 | robj *o = obj; 55 | serverAssert(o->type == OBJ_STRING); 56 | memset(p, 0, sizeof(*p)); 57 | 58 | if (sdsEncodedObject(o)) { 59 | p->ptr = o->ptr, p->len = sdslen(o->ptr); 60 | } else if (o->encoding == OBJ_ENCODING_INT) { 61 | p->val = (long)o->ptr; 62 | } else { 63 | serverPanic("Unknown string encoding."); 64 | } 65 | } 66 | 67 | size_t redisListObjectLen(void *obj) { 68 | robj *o = obj; 69 | serverAssert(o->type == OBJ_LIST); 70 | return listTypeLength(o); 71 | } 72 | 73 | size_t redisHashObjectLen(void *obj) { 74 | robj *o = obj; 75 | serverAssert(o->type == OBJ_HASH); 76 | return hashTypeLength(o); 77 | } 78 | 79 | size_t redisZsetObjectLen(void *obj) { 80 | robj *o = obj; 81 | serverAssert(o->type == OBJ_ZSET); 82 | return zsetLength(o); 83 | } 84 | 85 | size_t redisSetObjectLen(void *obj) { 86 | robj *o = obj; 87 | serverAssert(o->type == OBJ_SET); 88 | return setTypeSize(o); 89 | } 90 | -------------------------------------------------------------------------------- /pkg/rdb/cgo_redis.c: -------------------------------------------------------------------------------- 1 | #include "cgo_redis.h" 2 | 3 | extern void initServerConfig(void); 4 | extern void loadServerConfigFromString(char *config); 5 | extern void createSharedObjects(void); 6 | extern void initLazyfreeThreads(void); 7 | 8 | void initRedisServer(char *config) { 9 | initServerConfig(); 10 | createSharedObjects(); 11 | loadServerConfigFromString(config); 12 | initLazyfreeThreads(); 13 | } 14 | 15 | #include 16 | 17 | #define container_of(ptr, type, member) \ 18 | (type *)((char *)(ptr)-offsetof(type, member)); 19 | 20 | extern size_t onRedisRioRead(redisRio *p, void *buf, size_t len); 21 | static size_t rioRedisRioRead(rio *rdb, void *buf, size_t len) { 22 | redisRio *p = container_of(rdb, redisRio, rdb); 23 | while (len) { 24 | size_t remains = p->end - p->pos; 25 | if (remains != 0) { 26 | size_t nbytes = remains < len ? remains : len; 27 | memcpy(buf, p->buf + p->pos, nbytes); 28 | len -= nbytes, buf = (char *)buf + nbytes, p->pos += nbytes; 29 | } else if (len >= sizeof(p->buf)) { 30 | size_t nbytes = onRedisRioRead(p, buf, len); 31 | len -= nbytes, buf = (char *)buf + nbytes; 32 | } else { 33 | p->pos = 0; 34 | p->end = onRedisRioRead(p, p->buf, sizeof(p->buf)); 35 | } 36 | } 37 | return 1; 38 | } 39 | 40 | static size_t rioRedisRioWrite(rio *rdb, const void *buf, size_t len) { 41 | serverPanic("redisRio doesn't support write."); 42 | } 43 | 44 | static off_t rioRedisRioTell(rio *rdb) { 45 | serverPanic("redisRio doesn't support tell."); 46 | } 47 | 48 | static int rioRedisRioFlush(rio *rdb) { 49 | serverPanic("redisRio doesn't support flush."); 50 | } 51 | 52 | static const rio redisRioIO = { 53 | rioRedisRioRead, 54 | rioRedisRioWrite, 55 | rioRedisRioTell, 56 | rioRedisRioFlush, 57 | rioGenericUpdateChecksum, 58 | 0, /* current checksum */ 59 | 0, /* bytes read or written */ 60 | 0, /* read/write chunk size */ 61 | {{NULL, 0}}, /* union for io-specific vars */ 62 | }; 63 | 64 | void redisRioInit(redisRio *p) { 65 | p->rdb = redisRioIO; 66 | p->pos = p->end = 0; 67 | memset(p->buf, 0, sizeof(p->buf)); 68 | } 69 | 70 | int redisRioRead(redisRio *p, void *buf, size_t len) { 71 | return rioRead(&p->rdb, buf, len) != 0 ? 0 : -1; 72 | } 73 | 74 | int redisRioLoadLen(redisRio *p, uint64_t *len) { 75 | return (*len = rdbLoadLen(&p->rdb, NULL)) != RDB_LENERR ? 0 : -1; 76 | } 77 | 78 | int redisRioLoadType(redisRio *p, int *typ) { 79 | return (*typ = rdbLoadType(&p->rdb)) >= 0 ? 0 : -1; 80 | } 81 | 82 | int redisRioLoadTime(redisRio *p, time_t *val) { 83 | return (*val = rdbLoadTime(&p->rdb)) >= 0 ? 0 : -1; 84 | } 85 | 86 | extern long long rdbLoadMillisecondTime(rio *rdb); 87 | 88 | int redisRioLoadTimeMillisecond(redisRio *p, long long *val) { 89 | return (*val = rdbLoadMillisecondTime(&p->rdb)) >= 0 ? 0 : -1; 90 | } 91 | 92 | extern robj *rdbLoadZsetObject(int rdbtype, rio *rdb); 93 | 94 | void *redisRioLoadObject(redisRio *p, int typ) { 95 | switch (typ) { 96 | default: 97 | return rdbLoadObject(typ, &p->rdb); 98 | case RDB_TYPE_ZSET: 99 | case RDB_TYPE_ZSET_2: 100 | return rdbLoadZsetObject(typ, &p->rdb); 101 | } 102 | } 103 | 104 | void *redisRioLoadStringObject(redisRio *p) { 105 | return rdbLoadStringObject(&p->rdb); 106 | } 107 | -------------------------------------------------------------------------------- /pkg/rdb/cgo_redis.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void initRedisServer(char *config); 4 | 5 | /* API of Redis Rio/Rdb */ 6 | 7 | #define REDIS_RIO_BUFSIZE (1024 * 16) 8 | 9 | typedef struct { 10 | rio rdb; 11 | size_t pos, end; 12 | char buf[REDIS_RIO_BUFSIZE]; 13 | } redisRio; 14 | 15 | void redisRioInit(redisRio *p); 16 | 17 | int redisRioRead(redisRio *p, void *buf, size_t len); 18 | int redisRioLoadLen(redisRio *p, uint64_t *len); 19 | int redisRioLoadType(redisRio *p, int *typ); 20 | int redisRioLoadTime(redisRio *p, time_t *val); 21 | int redisRioLoadTimeMillisecond(redisRio *p, long long *val); 22 | 23 | void *redisRioLoadObject(redisRio *p, int typ); 24 | void *redisRioLoadStringObject(redisRio *p); 25 | 26 | inline uint64_t redisRioChecksum(redisRio *p) { return p->rdb.cksum; } 27 | 28 | /* API of Sds */ 29 | typedef struct { 30 | void *ptr; 31 | size_t len; 32 | long long val; 33 | double score; 34 | } redisSds; 35 | 36 | inline void redisSdsFreePtr(void *ptr) { sdsfree(ptr); } 37 | 38 | typedef struct { 39 | void *iter; 40 | struct { 41 | size_t len; 42 | redisSds buf[512]; 43 | } slice; 44 | size_t index; 45 | size_t (*load)(void *iter, redisSds *buf, size_t len); 46 | } redisTypeIterator; 47 | 48 | void redisTypeIteratorLoad(redisTypeIterator *p); 49 | 50 | /* API of redis Object */ 51 | int redisObjectType(void *obj); 52 | int redisObjectEncoding(void *obj); 53 | int redisObjectRefCount(void *obj); 54 | 55 | void redisObjectIncrRefCount(void *obj); 56 | void redisObjectDecrRefCount(void *obj, int lazyfree); 57 | 58 | void redisObjectCreateDumpPayload(void *obj, redisSds *p); 59 | void *redisObjectDecodeFromPayload(void *buf, size_t len); 60 | 61 | /* API of redis String */ 62 | size_t redisStringObjectLen(void *obj); 63 | void redisStringObjectLoad(void *obj, redisSds *sds); 64 | 65 | /* API of redis List */ 66 | size_t redisListObjectLen(void *obj); 67 | redisTypeIterator *redisListObjectNewIterator(void *obj); 68 | void redisListIteratorRelease(redisTypeIterator *p); 69 | 70 | /* API of redis Hash */ 71 | size_t redisHashObjectLen(void *obj); 72 | redisTypeIterator *redisHashObjectNewIterator(void *obj); 73 | void redisHashIteratorRelease(redisTypeIterator *p); 74 | 75 | /* API of redis Zset */ 76 | size_t redisZsetObjectLen(void *obj); 77 | redisTypeIterator *redisZsetObjectNewIterator(void *obj); 78 | void redisZsetIteratorRelease(redisTypeIterator *p); 79 | 80 | /* API of redis Set */ 81 | size_t redisSetObjectLen(void *obj); 82 | redisTypeIterator *redisSetObjectNewIterator(void *obj); 83 | void redisSetIteratorRelease(redisTypeIterator *p); 84 | 85 | /* API of redis zmalloc */ 86 | extern size_t zmalloc_used_memory(void); 87 | extern size_t zmalloc_memory_size(void); 88 | extern size_t zmalloc_get_rss(void); 89 | -------------------------------------------------------------------------------- /pkg/rdb/cgo_redis_test.go: -------------------------------------------------------------------------------- 1 | package rdb 2 | 3 | import ( 4 | "bytes" 5 | "reflect" 6 | "testing" 7 | "unsafe" 8 | 9 | "github.com/CodisLabs/codis/pkg/utils/assert" 10 | ) 11 | 12 | func TestRedisSds(t *testing.T) { 13 | var msg = []byte("hello world!!") 14 | var hdr = (*reflect.SliceHeader)(unsafe.Pointer(&msg)) 15 | var sds = &RedisSds{ 16 | Ptr: unsafe.Pointer(hdr.Data), 17 | Len: hdr.Len, 18 | } 19 | var s1 = sds.String() 20 | var p1 = (*reflect.StringHeader)(unsafe.Pointer(&s1)) 21 | assert.Must(s1 == string(msg)) 22 | assert.Must(p1.Data != hdr.Data) 23 | 24 | var s2 = sds.StringUnsafe() 25 | var p2 = (*reflect.StringHeader)(unsafe.Pointer(&s2)) 26 | assert.Must(s2 == string(msg)) 27 | assert.Must(p2.Data == hdr.Data) 28 | 29 | var s3 = sds.Bytes() 30 | var p3 = (*reflect.SliceHeader)(unsafe.Pointer(&s3)) 31 | assert.Must(bytes.Equal(s3, msg)) 32 | assert.Must(p3.Data != hdr.Data) 33 | 34 | var s4 = sds.BytesUnsafe() 35 | var p4 = (*reflect.SliceHeader)(unsafe.Pointer(&s4)) 36 | assert.Must(bytes.Equal(s4, msg)) 37 | assert.Must(p4.Data == hdr.Data) 38 | } 39 | -------------------------------------------------------------------------------- /pkg/rdb/testing/.gitignore: -------------------------------------------------------------------------------- 1 | !*.rdb 2 | -------------------------------------------------------------------------------- /pkg/rdb/testing/easily_compressible_string_key.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodisLabs/redis-port/a2e08c1edc05bdb7a2ad0ae29369f405f77eeaa1/pkg/rdb/testing/easily_compressible_string_key.rdb -------------------------------------------------------------------------------- /pkg/rdb/testing/empty_database.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodisLabs/redis-port/a2e08c1edc05bdb7a2ad0ae29369f405f77eeaa1/pkg/rdb/testing/empty_database.rdb -------------------------------------------------------------------------------- /pkg/rdb/testing/empty_database_nochecksum.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodisLabs/redis-port/a2e08c1edc05bdb7a2ad0ae29369f405f77eeaa1/pkg/rdb/testing/empty_database_nochecksum.rdb -------------------------------------------------------------------------------- /pkg/rdb/testing/hash_as_ziplist.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodisLabs/redis-port/a2e08c1edc05bdb7a2ad0ae29369f405f77eeaa1/pkg/rdb/testing/hash_as_ziplist.rdb -------------------------------------------------------------------------------- /pkg/rdb/testing/hash_table.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodisLabs/redis-port/a2e08c1edc05bdb7a2ad0ae29369f405f77eeaa1/pkg/rdb/testing/hash_table.rdb -------------------------------------------------------------------------------- /pkg/rdb/testing/integer_keys.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodisLabs/redis-port/a2e08c1edc05bdb7a2ad0ae29369f405f77eeaa1/pkg/rdb/testing/integer_keys.rdb -------------------------------------------------------------------------------- /pkg/rdb/testing/intset_16.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodisLabs/redis-port/a2e08c1edc05bdb7a2ad0ae29369f405f77eeaa1/pkg/rdb/testing/intset_16.rdb -------------------------------------------------------------------------------- /pkg/rdb/testing/intset_32.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodisLabs/redis-port/a2e08c1edc05bdb7a2ad0ae29369f405f77eeaa1/pkg/rdb/testing/intset_32.rdb -------------------------------------------------------------------------------- /pkg/rdb/testing/intset_64.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodisLabs/redis-port/a2e08c1edc05bdb7a2ad0ae29369f405f77eeaa1/pkg/rdb/testing/intset_64.rdb -------------------------------------------------------------------------------- /pkg/rdb/testing/keys_with_expiry.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodisLabs/redis-port/a2e08c1edc05bdb7a2ad0ae29369f405f77eeaa1/pkg/rdb/testing/keys_with_expiry.rdb -------------------------------------------------------------------------------- /pkg/rdb/testing/linkedlist.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodisLabs/redis-port/a2e08c1edc05bdb7a2ad0ae29369f405f77eeaa1/pkg/rdb/testing/linkedlist.rdb -------------------------------------------------------------------------------- /pkg/rdb/testing/list_decode.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodisLabs/redis-port/a2e08c1edc05bdb7a2ad0ae29369f405f77eeaa1/pkg/rdb/testing/list_decode.rdb -------------------------------------------------------------------------------- /pkg/rdb/testing/multiple_databases.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodisLabs/redis-port/a2e08c1edc05bdb7a2ad0ae29369f405f77eeaa1/pkg/rdb/testing/multiple_databases.rdb -------------------------------------------------------------------------------- /pkg/rdb/testing/non_ascii_values.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodisLabs/redis-port/a2e08c1edc05bdb7a2ad0ae29369f405f77eeaa1/pkg/rdb/testing/non_ascii_values.rdb -------------------------------------------------------------------------------- /pkg/rdb/testing/rdb_version_5_with_checksum.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodisLabs/redis-port/a2e08c1edc05bdb7a2ad0ae29369f405f77eeaa1/pkg/rdb/testing/rdb_version_5_with_checksum.rdb -------------------------------------------------------------------------------- /pkg/rdb/testing/rdb_version_8_with_64b_length_and_scores.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodisLabs/redis-port/a2e08c1edc05bdb7a2ad0ae29369f405f77eeaa1/pkg/rdb/testing/rdb_version_8_with_64b_length_and_scores.rdb -------------------------------------------------------------------------------- /pkg/rdb/testing/regular_set.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodisLabs/redis-port/a2e08c1edc05bdb7a2ad0ae29369f405f77eeaa1/pkg/rdb/testing/regular_set.rdb -------------------------------------------------------------------------------- /pkg/rdb/testing/regular_sorted_set.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodisLabs/redis-port/a2e08c1edc05bdb7a2ad0ae29369f405f77eeaa1/pkg/rdb/testing/regular_sorted_set.rdb -------------------------------------------------------------------------------- /pkg/rdb/testing/sorted_set_as_ziplist.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodisLabs/redis-port/a2e08c1edc05bdb7a2ad0ae29369f405f77eeaa1/pkg/rdb/testing/sorted_set_as_ziplist.rdb -------------------------------------------------------------------------------- /pkg/rdb/testing/uncompressible_string_keys.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodisLabs/redis-port/a2e08c1edc05bdb7a2ad0ae29369f405f77eeaa1/pkg/rdb/testing/uncompressible_string_keys.rdb -------------------------------------------------------------------------------- /pkg/rdb/testing/ziplist_that_compresses_easily.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodisLabs/redis-port/a2e08c1edc05bdb7a2ad0ae29369f405f77eeaa1/pkg/rdb/testing/ziplist_that_compresses_easily.rdb -------------------------------------------------------------------------------- /pkg/rdb/testing/ziplist_that_doesnt_compress.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodisLabs/redis-port/a2e08c1edc05bdb7a2ad0ae29369f405f77eeaa1/pkg/rdb/testing/ziplist_that_doesnt_compress.rdb -------------------------------------------------------------------------------- /pkg/rdb/testing/ziplist_with_integers.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodisLabs/redis-port/a2e08c1edc05bdb7a2ad0ae29369f405f77eeaa1/pkg/rdb/testing/ziplist_with_integers.rdb -------------------------------------------------------------------------------- /pkg/rdb/testing/zipmap_that_compresses_easily.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodisLabs/redis-port/a2e08c1edc05bdb7a2ad0ae29369f405f77eeaa1/pkg/rdb/testing/zipmap_that_compresses_easily.rdb -------------------------------------------------------------------------------- /pkg/rdb/testing/zipmap_that_doesnt_compress.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodisLabs/redis-port/a2e08c1edc05bdb7a2ad0ae29369f405f77eeaa1/pkg/rdb/testing/zipmap_that_doesnt_compress.rdb -------------------------------------------------------------------------------- /pkg/rdb/testing/zipmap_with_big_values.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodisLabs/redis-port/a2e08c1edc05bdb7a2ad0ae29369f405f77eeaa1/pkg/rdb/testing/zipmap_with_big_values.rdb -------------------------------------------------------------------------------- /vendor/github.com/CodisLabs/codis/pkg/proxy/redis/resp.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 CodisLabs. All Rights Reserved. 2 | // Licensed under the MIT (MIT-LICENSE.txt) license. 3 | 4 | package redis 5 | 6 | import "fmt" 7 | 8 | type RespType byte 9 | 10 | const ( 11 | TypeString RespType = '+' 12 | TypeError RespType = '-' 13 | TypeInt RespType = ':' 14 | TypeBulkBytes RespType = '$' 15 | TypeArray RespType = '*' 16 | ) 17 | 18 | func (t RespType) String() string { 19 | switch t { 20 | case TypeString: 21 | return "" 22 | case TypeError: 23 | return "" 24 | case TypeInt: 25 | return "" 26 | case TypeBulkBytes: 27 | return "" 28 | case TypeArray: 29 | return "" 30 | default: 31 | return fmt.Sprintf("", byte(t)) 32 | } 33 | } 34 | 35 | type Resp struct { 36 | Type RespType 37 | 38 | Value []byte 39 | Array []*Resp 40 | } 41 | 42 | func (r *Resp) IsString() bool { 43 | return r.Type == TypeString 44 | } 45 | 46 | func (r *Resp) IsError() bool { 47 | return r.Type == TypeError 48 | } 49 | 50 | func (r *Resp) IsInt() bool { 51 | return r.Type == TypeInt 52 | } 53 | 54 | func (r *Resp) IsBulkBytes() bool { 55 | return r.Type == TypeBulkBytes 56 | } 57 | 58 | func (r *Resp) IsArray() bool { 59 | return r.Type == TypeArray 60 | } 61 | 62 | func NewString(value []byte) *Resp { 63 | r := &Resp{} 64 | r.Type = TypeString 65 | r.Value = value 66 | return r 67 | } 68 | 69 | func NewError(value []byte) *Resp { 70 | r := &Resp{} 71 | r.Type = TypeError 72 | r.Value = value 73 | return r 74 | } 75 | 76 | func NewErrorf(format string, args ...interface{}) *Resp { 77 | return NewError([]byte(fmt.Sprintf(format, args...))) 78 | } 79 | 80 | func NewInt(value []byte) *Resp { 81 | r := &Resp{} 82 | r.Type = TypeInt 83 | r.Value = value 84 | return r 85 | } 86 | 87 | func NewBulkBytes(value []byte) *Resp { 88 | r := &Resp{} 89 | r.Type = TypeBulkBytes 90 | r.Value = value 91 | return r 92 | } 93 | 94 | func NewArray(array []*Resp) *Resp { 95 | r := &Resp{} 96 | r.Type = TypeArray 97 | r.Array = array 98 | return r 99 | } 100 | -------------------------------------------------------------------------------- /vendor/github.com/CodisLabs/codis/pkg/utils/assert/assert.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 CodisLabs. All Rights Reserved. 2 | // Licensed under the MIT (MIT-LICENSE.txt) license. 3 | 4 | package assert 5 | 6 | import "github.com/CodisLabs/codis/pkg/utils/log" 7 | 8 | func Must(b bool) { 9 | if b { 10 | return 11 | } 12 | log.Panic("assertion failed") 13 | } 14 | 15 | func MustNoError(err error) { 16 | if err == nil { 17 | return 18 | } 19 | log.PanicError(err, "error happens, assertion failed") 20 | } 21 | -------------------------------------------------------------------------------- /vendor/github.com/CodisLabs/codis/pkg/utils/bufio2/slice.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 CodisLabs. All Rights Reserved. 2 | // Licensed under the MIT (MIT-LICENSE.txt) license. 3 | 4 | package bufio2 5 | 6 | type sliceAlloc struct { 7 | buf []byte 8 | } 9 | 10 | func (d *sliceAlloc) Make(n int) (ss []byte) { 11 | switch { 12 | case n == 0: 13 | return []byte{} 14 | case n >= 512: 15 | return make([]byte, n) 16 | default: 17 | if len(d.buf) < n { 18 | d.buf = make([]byte, 8192) 19 | } 20 | ss, d.buf = d.buf[:n:n], d.buf[n:] 21 | return ss 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /vendor/github.com/CodisLabs/codis/pkg/utils/errors/errors.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 CodisLabs. All Rights Reserved. 2 | // Licensed under the MIT (MIT-LICENSE.txt) license. 3 | 4 | package errors 5 | 6 | import ( 7 | "errors" 8 | "fmt" 9 | 10 | "github.com/CodisLabs/codis/pkg/utils/trace" 11 | ) 12 | 13 | var TraceEnabled = true 14 | 15 | type TracedError struct { 16 | Stack trace.Stack 17 | Cause error 18 | } 19 | 20 | func (e *TracedError) Error() string { 21 | return e.Cause.Error() 22 | } 23 | 24 | func New(s string) error { 25 | return errors.New(s) 26 | } 27 | 28 | func Trace(err error) error { 29 | if err == nil || !TraceEnabled { 30 | return err 31 | } 32 | _, ok := err.(*TracedError) 33 | if ok { 34 | return err 35 | } 36 | return &TracedError{ 37 | Stack: trace.TraceN(1, 32), 38 | Cause: err, 39 | } 40 | } 41 | 42 | func Errorf(format string, v ...interface{}) error { 43 | err := fmt.Errorf(format, v...) 44 | if !TraceEnabled { 45 | return err 46 | } 47 | return &TracedError{ 48 | Stack: trace.TraceN(1, 32), 49 | Cause: err, 50 | } 51 | } 52 | 53 | func Stack(err error) trace.Stack { 54 | if err == nil { 55 | return nil 56 | } 57 | e, ok := err.(*TracedError) 58 | if ok { 59 | return e.Stack 60 | } 61 | return nil 62 | } 63 | 64 | func Cause(err error) error { 65 | for err != nil { 66 | e, ok := err.(*TracedError) 67 | if ok { 68 | err = e.Cause 69 | } else { 70 | return err 71 | } 72 | } 73 | return nil 74 | } 75 | 76 | func Equal(err1, err2 error) bool { 77 | e1 := Cause(err1) 78 | e2 := Cause(err2) 79 | if e1 == e2 { 80 | return true 81 | } 82 | if e1 == nil || e2 == nil { 83 | return e1 == e2 84 | } 85 | return e1.Error() == e2.Error() 86 | } 87 | 88 | func NotEqual(err1, err2 error) bool { 89 | return !Equal(err1, err2) 90 | } 91 | -------------------------------------------------------------------------------- /vendor/github.com/CodisLabs/codis/pkg/utils/log/rolling.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 CodisLabs. All Rights Reserved. 2 | // Licensed under the MIT (MIT-LICENSE.txt) license. 3 | 4 | package log 5 | 6 | import ( 7 | "fmt" 8 | "io" 9 | "os" 10 | "path/filepath" 11 | "sync" 12 | "time" 13 | 14 | "github.com/CodisLabs/codis/pkg/utils/errors" 15 | ) 16 | 17 | type rollingFile struct { 18 | mu sync.Mutex 19 | 20 | closed bool 21 | 22 | file *os.File 23 | basePath string 24 | filePath string 25 | fileFrag string 26 | 27 | rolling RollingFormat 28 | } 29 | 30 | var ErrClosedRollingFile = errors.New("rolling file is closed") 31 | 32 | type RollingFormat string 33 | 34 | const ( 35 | MonthlyRolling RollingFormat = "2006-01" 36 | DailyRolling = "2006-01-02" 37 | HourlyRolling = "2006-01-02-15" 38 | MinutelyRolling = "2006-01-02-15-04" 39 | SecondlyRolling = "2006-01-02-15-04-05" 40 | ) 41 | 42 | func (r *rollingFile) roll() error { 43 | suffix := time.Now().Format(string(r.rolling)) 44 | if r.file != nil { 45 | if suffix == r.fileFrag { 46 | return nil 47 | } 48 | r.file.Close() 49 | r.file = nil 50 | } 51 | r.fileFrag = suffix 52 | r.filePath = fmt.Sprintf("%s.%s", r.basePath, r.fileFrag) 53 | 54 | if dir, _ := filepath.Split(r.basePath); dir != "" && dir != "." { 55 | if err := os.MkdirAll(dir, 0777); err != nil { 56 | return errors.Trace(err) 57 | } 58 | } 59 | 60 | f, err := os.OpenFile(r.filePath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) 61 | if err != nil { 62 | return errors.Trace(err) 63 | } else { 64 | r.file = f 65 | return nil 66 | } 67 | } 68 | 69 | func (r *rollingFile) Close() error { 70 | r.mu.Lock() 71 | defer r.mu.Unlock() 72 | 73 | if r.closed { 74 | return nil 75 | } 76 | 77 | r.closed = true 78 | if f := r.file; f != nil { 79 | r.file = nil 80 | return errors.Trace(f.Close()) 81 | } 82 | return nil 83 | } 84 | 85 | func (r *rollingFile) Write(b []byte) (int, error) { 86 | r.mu.Lock() 87 | defer r.mu.Unlock() 88 | 89 | if r.closed { 90 | return 0, errors.Trace(ErrClosedRollingFile) 91 | } 92 | 93 | if err := r.roll(); err != nil { 94 | return 0, err 95 | } 96 | 97 | n, err := r.file.Write(b) 98 | if err != nil { 99 | return n, errors.Trace(err) 100 | } else { 101 | return n, nil 102 | } 103 | } 104 | 105 | func NewRollingFile(basePath string, rolling RollingFormat) (io.WriteCloser, error) { 106 | if _, file := filepath.Split(basePath); file == "" { 107 | return nil, errors.Errorf("invalid base-path = %s, file name is required", basePath) 108 | } 109 | return &rollingFile{basePath: basePath, rolling: rolling}, nil 110 | } 111 | -------------------------------------------------------------------------------- /vendor/github.com/CodisLabs/codis/pkg/utils/sync2/atomic2/atomic64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 CodisLabs. All Rights Reserved. 2 | // Licensed under the MIT (MIT-LICENSE.txt) license. 3 | 4 | package atomic2 5 | 6 | import "sync/atomic" 7 | 8 | type Int64 int64 9 | 10 | func (a *Int64) Int64() int64 { 11 | return atomic.LoadInt64((*int64)(a)) 12 | } 13 | 14 | func (a *Int64) AsInt() int { 15 | return int(a.Int64()) 16 | } 17 | 18 | func (a *Int64) Set(v int64) { 19 | atomic.StoreInt64((*int64)(a), v) 20 | } 21 | 22 | func (a *Int64) CompareAndSwap(o, n int64) bool { 23 | return atomic.CompareAndSwapInt64((*int64)(a), o, n) 24 | } 25 | 26 | func (a *Int64) Swap(v int64) int64 { 27 | return atomic.SwapInt64((*int64)(a), v) 28 | } 29 | 30 | func (a *Int64) Add(v int64) int64 { 31 | return atomic.AddInt64((*int64)(a), v) 32 | } 33 | 34 | func (a *Int64) Sub(v int64) int64 { 35 | return a.Add(-v) 36 | } 37 | 38 | func (a *Int64) Incr() int64 { 39 | return a.Add(1) 40 | } 41 | 42 | func (a *Int64) Decr() int64 { 43 | return a.Add(-1) 44 | } 45 | -------------------------------------------------------------------------------- /vendor/github.com/CodisLabs/codis/pkg/utils/sync2/atomic2/bool.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 CodisLabs. All Rights Reserved. 2 | // Licensed under the MIT (MIT-LICENSE.txt) license. 3 | 4 | package atomic2 5 | 6 | type Bool struct { 7 | c Int64 8 | } 9 | 10 | func (b *Bool) Bool() bool { 11 | return b.IsTrue() 12 | } 13 | 14 | func (b *Bool) IsTrue() bool { 15 | return b.c.Int64() != 0 16 | } 17 | 18 | func (b *Bool) IsFalse() bool { 19 | return b.c.Int64() == 0 20 | } 21 | 22 | func (b *Bool) toInt64(v bool) int64 { 23 | if v { 24 | return 1 25 | } else { 26 | return 0 27 | } 28 | } 29 | 30 | func (b *Bool) Set(v bool) { 31 | b.c.Set(b.toInt64(v)) 32 | } 33 | 34 | func (b *Bool) CompareAndSwap(o, n bool) bool { 35 | return b.c.CompareAndSwap(b.toInt64(o), b.toInt64(n)) 36 | } 37 | 38 | func (b *Bool) Swap(v bool) bool { 39 | return b.c.Swap(b.toInt64(v)) != 0 40 | } 41 | -------------------------------------------------------------------------------- /vendor/github.com/CodisLabs/codis/pkg/utils/trace/trace.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 CodisLabs. All Rights Reserved. 2 | // Licensed under the MIT (MIT-LICENSE.txt) license. 3 | 4 | package trace 5 | 6 | import ( 7 | "bytes" 8 | "fmt" 9 | "runtime" 10 | "strings" 11 | ) 12 | 13 | const ( 14 | tab = " " 15 | ) 16 | 17 | type Record struct { 18 | Name string 19 | File string 20 | Line int 21 | } 22 | 23 | func (r *Record) String() string { 24 | if r == nil { 25 | return "[nil-record]" 26 | } 27 | return fmt.Sprintf("%s:%d %s", r.File, r.Line, r.Name) 28 | } 29 | 30 | type Stack []*Record 31 | 32 | func Trace() Stack { 33 | return TraceN(1, 32) 34 | } 35 | 36 | func (s Stack) String() string { 37 | return s.StringWithIndent(0) 38 | } 39 | 40 | func (s Stack) StringWithIndent(indent int) string { 41 | var b bytes.Buffer 42 | for i, r := range s { 43 | for j := 0; j < indent; j++ { 44 | fmt.Fprint(&b, tab) 45 | } 46 | fmt.Fprintf(&b, "%-3d %s:%d\n", len(s)-i-1, r.File, r.Line) 47 | for j := 0; j < indent; j++ { 48 | fmt.Fprint(&b, tab) 49 | } 50 | fmt.Fprint(&b, tab, tab) 51 | fmt.Fprint(&b, r.Name, "\n") 52 | } 53 | if len(s) != 0 { 54 | for j := 0; j < indent; j++ { 55 | fmt.Fprint(&b, tab) 56 | } 57 | fmt.Fprint(&b, tab, "... ...\n") 58 | } 59 | return b.String() 60 | } 61 | 62 | func TraceN(skip, depth int) Stack { 63 | s := make([]*Record, 0, depth) 64 | for i := 0; i < depth; i++ { 65 | r := Caller(skip + i + 1) 66 | if r == nil { 67 | break 68 | } 69 | s = append(s, r) 70 | } 71 | return s 72 | } 73 | 74 | func Caller(skip int) *Record { 75 | pc, file, line, ok := runtime.Caller(skip + 1) 76 | if !ok { 77 | return nil 78 | } 79 | fn := runtime.FuncForPC(pc) 80 | if fn == nil || strings.HasPrefix(fn.Name(), "runtime.") { 81 | return nil 82 | } 83 | return &Record{ 84 | Name: fn.Name(), 85 | File: file, 86 | Line: line, 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/CodisLabs/codis/pkg/utils/unsafe2/cgo_malloc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 CodisLabs. All Rights Reserved. 2 | // Licensed under the MIT (MIT-LICENSE.txt) license. 3 | 4 | // +build !cgo_jemalloc 5 | 6 | package unsafe2 7 | 8 | // #include 9 | import "C" 10 | 11 | import ( 12 | "unsafe" 13 | ) 14 | 15 | func cgo_malloc(n int) unsafe.Pointer { 16 | return C.malloc(C.size_t(n)) 17 | } 18 | 19 | func cgo_free(ptr unsafe.Pointer) { 20 | C.free(ptr) 21 | } 22 | -------------------------------------------------------------------------------- /vendor/github.com/CodisLabs/codis/pkg/utils/unsafe2/cgo_slice.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 CodisLabs. All Rights Reserved. 2 | // Licensed under the MIT (MIT-LICENSE.txt) license. 3 | 4 | package unsafe2 5 | 6 | import ( 7 | "reflect" 8 | "runtime" 9 | "unsafe" 10 | 11 | "github.com/CodisLabs/codis/pkg/utils/sync2/atomic2" 12 | ) 13 | 14 | var allocOffheapBytes atomic2.Int64 15 | 16 | func OffheapBytes() int64 { 17 | return allocOffheapBytes.Int64() 18 | } 19 | 20 | type cgoSlice struct { 21 | ptr unsafe.Pointer 22 | buf []byte 23 | } 24 | 25 | func newCGoSlice(n int, force bool) Slice { 26 | after := allocOffheapBytes.Add(int64(n)) 27 | if !force && after > MaxOffheapBytes() { 28 | allocOffheapBytes.Sub(int64(n)) 29 | return nil 30 | } 31 | p := cgo_malloc(n) 32 | if p == nil { 33 | allocOffheapBytes.Sub(int64(n)) 34 | return nil 35 | } 36 | s := &cgoSlice{ 37 | ptr: p, 38 | buf: *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{ 39 | Data: uintptr(p), Len: n, Cap: n, 40 | })), 41 | } 42 | runtime.SetFinalizer(s, (*cgoSlice).reclaim) 43 | return s 44 | } 45 | 46 | func (s *cgoSlice) Type() string { 47 | return "cgo_slice" 48 | } 49 | 50 | func (s *cgoSlice) Buffer() []byte { 51 | return s.buf 52 | } 53 | 54 | func (s *cgoSlice) reclaim() { 55 | if s.ptr == nil { 56 | return 57 | } 58 | cgo_free(s.ptr) 59 | allocOffheapBytes.Sub(int64(len(s.buf))) 60 | s.ptr = nil 61 | s.buf = nil 62 | runtime.SetFinalizer(s, nil) 63 | } 64 | 65 | func (s *cgoSlice) Slice2(beg, end int) Slice { 66 | return newGoSliceFrom(s, s.Buffer()[beg:end]) 67 | } 68 | 69 | func (s *cgoSlice) Slice3(beg, end, cap int) Slice { 70 | return newGoSliceFrom(s, s.Buffer()[beg:end:cap]) 71 | } 72 | 73 | func (s *cgoSlice) Parent() Slice { 74 | return nil 75 | } 76 | -------------------------------------------------------------------------------- /vendor/github.com/CodisLabs/codis/pkg/utils/unsafe2/go_slice.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 CodisLabs. All Rights Reserved. 2 | // Licensed under the MIT (MIT-LICENSE.txt) license. 3 | 4 | package unsafe2 5 | 6 | type goSlice struct { 7 | buf []byte 8 | 9 | parent Slice 10 | } 11 | 12 | func newGoSlice(n int) Slice { 13 | return &goSlice{ 14 | buf: make([]byte, n), 15 | } 16 | } 17 | 18 | func newGoSliceFrom(parent Slice, buf []byte) Slice { 19 | return &goSlice{ 20 | buf: buf, parent: parent, 21 | } 22 | } 23 | 24 | func (s *goSlice) Type() string { 25 | return "go_slice" 26 | } 27 | 28 | func (s *goSlice) Buffer() []byte { 29 | return s.buf 30 | } 31 | 32 | func (s *goSlice) reclaim() { 33 | } 34 | 35 | func (s *goSlice) Slice2(beg, end int) Slice { 36 | return newGoSliceFrom(s.parent, s.buf[beg:end]) 37 | } 38 | 39 | func (s *goSlice) Slice3(beg, end, cap int) Slice { 40 | return newGoSliceFrom(s.parent, s.buf[beg:end:cap]) 41 | } 42 | 43 | func (s *goSlice) Parent() Slice { 44 | return s.parent 45 | } 46 | -------------------------------------------------------------------------------- /vendor/github.com/CodisLabs/codis/pkg/utils/unsafe2/je_malloc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 CodisLabs. All Rights Reserved. 2 | // Licensed under the MIT (MIT-LICENSE.txt) license. 3 | 4 | // +build cgo_jemalloc 5 | 6 | package unsafe2 7 | 8 | import ( 9 | "unsafe" 10 | 11 | jemalloc "github.com/spinlock/jemalloc-go" 12 | ) 13 | 14 | func cgo_malloc(n int) unsafe.Pointer { 15 | return jemalloc.Malloc(n) 16 | } 17 | 18 | func cgo_free(ptr unsafe.Pointer) { 19 | jemalloc.Free(ptr) 20 | } 21 | -------------------------------------------------------------------------------- /vendor/github.com/CodisLabs/codis/pkg/utils/unsafe2/slice.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 CodisLabs. All Rights Reserved. 2 | // Licensed under the MIT (MIT-LICENSE.txt) license. 3 | 4 | package unsafe2 5 | 6 | import "github.com/CodisLabs/codis/pkg/utils/sync2/atomic2" 7 | 8 | type Slice interface { 9 | Type() string 10 | 11 | Buffer() []byte 12 | reclaim() 13 | 14 | Slice2(beg, end int) Slice 15 | Slice3(beg, end, cap int) Slice 16 | Parent() Slice 17 | } 18 | 19 | var maxOffheapBytes atomic2.Int64 20 | 21 | func MaxOffheapBytes() int64 { 22 | return maxOffheapBytes.Int64() 23 | } 24 | 25 | func SetMaxOffheapBytes(n int64) { 26 | maxOffheapBytes.Set(n) 27 | } 28 | 29 | const MinOffheapSlice = 1024 * 16 30 | 31 | func MakeSlice(n int) Slice { 32 | if n >= MinOffheapSlice { 33 | if s := newCGoSlice(n, false); s != nil { 34 | return s 35 | } 36 | } 37 | return newGoSlice(n) 38 | } 39 | 40 | func MakeOffheapSlice(n int) Slice { 41 | if n >= 0 { 42 | return newCGoSlice(n, true) 43 | } 44 | panic("make slice with negative size") 45 | } 46 | 47 | func FreeSlice(s Slice) { 48 | if s != nil { 49 | s.reclaim() 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /vendor/github.com/CodisLabs/codis/pkg/utils/unsafe2/string.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 CodisLabs. All Rights Reserved. 2 | // Licensed under the MIT (MIT-LICENSE.txt) license. 3 | 4 | package unsafe2 5 | 6 | import ( 7 | "reflect" 8 | "unsafe" 9 | ) 10 | 11 | func CastString(b []byte) string { 12 | if len(b) == 0 { 13 | return "" 14 | } 15 | var ptr = (*reflect.SliceHeader)(unsafe.Pointer(&b)) 16 | var h = &reflect.StringHeader{ 17 | Data: uintptr(ptr.Data), Len: ptr.Len, 18 | } 19 | return *(*string)(unsafe.Pointer(h)) 20 | } 21 | -------------------------------------------------------------------------------- /vendor/github.com/docopt/docopt-go/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | 24 | # coverage droppings 25 | profile.cov 26 | -------------------------------------------------------------------------------- /vendor/github.com/docopt/docopt-go/.travis.yml: -------------------------------------------------------------------------------- 1 | # Travis CI (http://travis-ci.org/) is a continuous integration 2 | # service for open source projects. This file configures it 3 | # to run unit tests for docopt-go. 4 | 5 | language: go 6 | 7 | go: 8 | - 1.4 9 | - 1.5 10 | - tip 11 | 12 | matrix: 13 | fast_finish: true 14 | 15 | before_install: 16 | - go get golang.org/x/tools/cmd/vet 17 | - go get golang.org/x/tools/cmd/cover 18 | - go get github.com/golang/lint/golint 19 | - go get github.com/mattn/goveralls 20 | 21 | install: 22 | - go get -d -v ./... && go build -v ./... 23 | 24 | script: 25 | - go vet -x ./... 26 | - $HOME/gopath/bin/golint ./... 27 | - go test -v ./... 28 | - go test -covermode=count -coverprofile=profile.cov . 29 | 30 | after_script: 31 | - $HOME/gopath/bin/goveralls -coverprofile=profile.cov -service=travis-ci 32 | -------------------------------------------------------------------------------- /vendor/github.com/docopt/docopt-go/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Keith Batten 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /vendor/github.com/docopt/docopt-go/README.md: -------------------------------------------------------------------------------- 1 | docopt-go 2 | ========= 3 | 4 | [![Build Status](https://travis-ci.org/docopt/docopt.go.svg?branch=master)](https://travis-ci.org/docopt/docopt.go) 5 | [![Coverage Status](https://coveralls.io/repos/docopt/docopt.go/badge.png)](https://coveralls.io/r/docopt/docopt.go) 6 | [![GoDoc](https://godoc.org/github.com/docopt/docopt.go?status.png)](https://godoc.org/github.com/docopt/docopt.go) 7 | 8 | An implementation of [docopt](http://docopt.org/) in the 9 | [Go](http://golang.org/) programming language. 10 | 11 | **docopt** helps you create *beautiful* command-line interfaces easily: 12 | 13 | ```go 14 | package main 15 | 16 | import ( 17 | "fmt" 18 | "github.com/docopt/docopt-go" 19 | ) 20 | 21 | func main() { 22 | usage := `Naval Fate. 23 | 24 | Usage: 25 | naval_fate ship new ... 26 | naval_fate ship move [--speed=] 27 | naval_fate ship shoot 28 | naval_fate mine (set|remove) [--moored|--drifting] 29 | naval_fate -h | --help 30 | naval_fate --version 31 | 32 | Options: 33 | -h --help Show this screen. 34 | --version Show version. 35 | --speed= Speed in knots [default: 10]. 36 | --moored Moored (anchored) mine. 37 | --drifting Drifting mine.` 38 | 39 | arguments, _ := docopt.Parse(usage, nil, true, "Naval Fate 2.0", false) 40 | fmt.Println(arguments) 41 | } 42 | ``` 43 | 44 | **docopt** parses command-line arguments based on a help message. Don't 45 | write parser code: a good help message already has all the necessary 46 | information in it. 47 | 48 | ## Installation 49 | 50 | ⚠ Use the alias “docopt-go”. To use docopt in your Go code: 51 | 52 | ```go 53 | import "github.com/docopt/docopt-go" 54 | ``` 55 | 56 | To install docopt according to your `$GOPATH`: 57 | 58 | ```console 59 | $ go get github.com/docopt/docopt-go 60 | ``` 61 | 62 | ## API 63 | 64 | ```go 65 | func Parse(doc string, argv []string, help bool, version string, 66 | optionsFirst bool, exit ...bool) (map[string]interface{}, error) 67 | ``` 68 | Parse `argv` based on the command-line interface described in `doc`. 69 | 70 | Given a conventional command-line help message, docopt creates a parser and 71 | processes the arguments. See 72 | https://github.com/docopt/docopt#help-message-format for a description of the 73 | help message format. If `argv` is `nil`, `os.Args[1:]` is used. 74 | 75 | docopt returns a map of option names to the values parsed from `argv`, and an 76 | error or `nil`. 77 | 78 | More documentation for docopt is available at 79 | [GoDoc.org](https://godoc.org/github.com/docopt/docopt.go). 80 | 81 | ## Testing 82 | 83 | All tests from the Python version are implemented and passing 84 | at [Travis CI](https://travis-ci.org/docopt/docopt.go). New 85 | language-agnostic tests have been added 86 | to [test_golang.docopt](test_golang.docopt). 87 | 88 | To run tests for docopt-go, use `go test`. 89 | -------------------------------------------------------------------------------- /vendor/github.com/docopt/docopt-go/test_golang.docopt: -------------------------------------------------------------------------------- 1 | r"""usage: prog [NAME_-2]...""" 2 | $ prog 10 20 3 | {"NAME_-2": ["10", "20"]} 4 | 5 | $ prog 10 6 | {"NAME_-2": ["10"]} 7 | 8 | $ prog 9 | {"NAME_-2": []} 10 | -------------------------------------------------------------------------------- /vendor/github.com/garyburd/redigo/internal/commandinfo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 Gary Burd 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 | // not use this file except in compliance with the License. You may obtain 5 | // a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | package internal 16 | 17 | import ( 18 | "strings" 19 | ) 20 | 21 | const ( 22 | WatchState = 1 << iota 23 | MultiState 24 | SubscribeState 25 | MonitorState 26 | ) 27 | 28 | type CommandInfo struct { 29 | Set, Clear int 30 | } 31 | 32 | var commandInfos = map[string]CommandInfo{ 33 | "WATCH": {Set: WatchState}, 34 | "UNWATCH": {Clear: WatchState}, 35 | "MULTI": {Set: MultiState}, 36 | "EXEC": {Clear: WatchState | MultiState}, 37 | "DISCARD": {Clear: WatchState | MultiState}, 38 | "PSUBSCRIBE": {Set: SubscribeState}, 39 | "SUBSCRIBE": {Set: SubscribeState}, 40 | "MONITOR": {Set: MonitorState}, 41 | } 42 | 43 | func init() { 44 | for n, ci := range commandInfos { 45 | commandInfos[strings.ToLower(n)] = ci 46 | } 47 | } 48 | 49 | func LookupCommandInfo(commandName string) CommandInfo { 50 | if ci, ok := commandInfos[commandName]; ok { 51 | return ci 52 | } 53 | return commandInfos[strings.ToUpper(commandName)] 54 | } 55 | -------------------------------------------------------------------------------- /vendor/github.com/garyburd/redigo/redis/go17.go: -------------------------------------------------------------------------------- 1 | // +build go1.7 2 | 3 | package redis 4 | 5 | import "crypto/tls" 6 | 7 | // similar cloneTLSClientConfig in the stdlib, but also honor skipVerify for the nil case 8 | func cloneTLSClientConfig(cfg *tls.Config, skipVerify bool) *tls.Config { 9 | if cfg == nil { 10 | return &tls.Config{InsecureSkipVerify: skipVerify} 11 | } 12 | return &tls.Config{ 13 | Rand: cfg.Rand, 14 | Time: cfg.Time, 15 | Certificates: cfg.Certificates, 16 | NameToCertificate: cfg.NameToCertificate, 17 | GetCertificate: cfg.GetCertificate, 18 | RootCAs: cfg.RootCAs, 19 | NextProtos: cfg.NextProtos, 20 | ServerName: cfg.ServerName, 21 | ClientAuth: cfg.ClientAuth, 22 | ClientCAs: cfg.ClientCAs, 23 | InsecureSkipVerify: cfg.InsecureSkipVerify, 24 | CipherSuites: cfg.CipherSuites, 25 | PreferServerCipherSuites: cfg.PreferServerCipherSuites, 26 | ClientSessionCache: cfg.ClientSessionCache, 27 | MinVersion: cfg.MinVersion, 28 | MaxVersion: cfg.MaxVersion, 29 | CurvePreferences: cfg.CurvePreferences, 30 | DynamicRecordSizingDisabled: cfg.DynamicRecordSizingDisabled, 31 | Renegotiation: cfg.Renegotiation, 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /vendor/github.com/garyburd/redigo/redis/pre_go17.go: -------------------------------------------------------------------------------- 1 | // +build !go1.7 2 | 3 | package redis 4 | 5 | import "crypto/tls" 6 | 7 | // similar cloneTLSClientConfig in the stdlib, but also honor skipVerify for the nil case 8 | func cloneTLSClientConfig(cfg *tls.Config, skipVerify bool) *tls.Config { 9 | if cfg == nil { 10 | return &tls.Config{InsecureSkipVerify: skipVerify} 11 | } 12 | return &tls.Config{ 13 | Rand: cfg.Rand, 14 | Time: cfg.Time, 15 | Certificates: cfg.Certificates, 16 | NameToCertificate: cfg.NameToCertificate, 17 | GetCertificate: cfg.GetCertificate, 18 | RootCAs: cfg.RootCAs, 19 | NextProtos: cfg.NextProtos, 20 | ServerName: cfg.ServerName, 21 | ClientAuth: cfg.ClientAuth, 22 | ClientCAs: cfg.ClientCAs, 23 | InsecureSkipVerify: cfg.InsecureSkipVerify, 24 | CipherSuites: cfg.CipherSuites, 25 | PreferServerCipherSuites: cfg.PreferServerCipherSuites, 26 | ClientSessionCache: cfg.ClientSessionCache, 27 | MinVersion: cfg.MinVersion, 28 | MaxVersion: cfg.MaxVersion, 29 | CurvePreferences: cfg.CurvePreferences, 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /vendor/github.com/garyburd/redigo/redis/redis.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Gary Burd 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 | // not use this file except in compliance with the License. You may obtain 5 | // a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | package redis 16 | 17 | // Error represents an error returned in a command reply. 18 | type Error string 19 | 20 | func (err Error) Error() string { return string(err) } 21 | 22 | // Conn represents a connection to a Redis server. 23 | type Conn interface { 24 | // Close closes the connection. 25 | Close() error 26 | 27 | // Err returns a non-nil value when the connection is not usable. 28 | Err() error 29 | 30 | // Do sends a command to the server and returns the received reply. 31 | Do(commandName string, args ...interface{}) (reply interface{}, err error) 32 | 33 | // Send writes the command to the client's output buffer. 34 | Send(commandName string, args ...interface{}) error 35 | 36 | // Flush flushes the output buffer to the Redis server. 37 | Flush() error 38 | 39 | // Receive receives a single reply from the Redis server 40 | Receive() (reply interface{}, err error) 41 | } 42 | -------------------------------------------------------------------------------- /vendor/github.com/garyburd/redigo/redis/script.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 Gary Burd 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 | // not use this file except in compliance with the License. You may obtain 5 | // a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | package redis 16 | 17 | import ( 18 | "crypto/sha1" 19 | "encoding/hex" 20 | "io" 21 | "strings" 22 | ) 23 | 24 | // Script encapsulates the source, hash and key count for a Lua script. See 25 | // http://redis.io/commands/eval for information on scripts in Redis. 26 | type Script struct { 27 | keyCount int 28 | src string 29 | hash string 30 | } 31 | 32 | // NewScript returns a new script object. If keyCount is greater than or equal 33 | // to zero, then the count is automatically inserted in the EVAL command 34 | // argument list. If keyCount is less than zero, then the application supplies 35 | // the count as the first value in the keysAndArgs argument to the Do, Send and 36 | // SendHash methods. 37 | func NewScript(keyCount int, src string) *Script { 38 | h := sha1.New() 39 | io.WriteString(h, src) 40 | return &Script{keyCount, src, hex.EncodeToString(h.Sum(nil))} 41 | } 42 | 43 | func (s *Script) args(spec string, keysAndArgs []interface{}) []interface{} { 44 | var args []interface{} 45 | if s.keyCount < 0 { 46 | args = make([]interface{}, 1+len(keysAndArgs)) 47 | args[0] = spec 48 | copy(args[1:], keysAndArgs) 49 | } else { 50 | args = make([]interface{}, 2+len(keysAndArgs)) 51 | args[0] = spec 52 | args[1] = s.keyCount 53 | copy(args[2:], keysAndArgs) 54 | } 55 | return args 56 | } 57 | 58 | // Do evaluates the script. Under the covers, Do optimistically evaluates the 59 | // script using the EVALSHA command. If the command fails because the script is 60 | // not loaded, then Do evaluates the script using the EVAL command (thus 61 | // causing the script to load). 62 | func (s *Script) Do(c Conn, keysAndArgs ...interface{}) (interface{}, error) { 63 | v, err := c.Do("EVALSHA", s.args(s.hash, keysAndArgs)...) 64 | if e, ok := err.(Error); ok && strings.HasPrefix(string(e), "NOSCRIPT ") { 65 | v, err = c.Do("EVAL", s.args(s.src, keysAndArgs)...) 66 | } 67 | return v, err 68 | } 69 | 70 | // SendHash evaluates the script without waiting for the reply. The script is 71 | // evaluated with the EVALSHA command. The application must ensure that the 72 | // script is loaded by a previous call to Send, Do or Load methods. 73 | func (s *Script) SendHash(c Conn, keysAndArgs ...interface{}) error { 74 | return c.Send("EVALSHA", s.args(s.hash, keysAndArgs)...) 75 | } 76 | 77 | // Send evaluates the script without waiting for the reply. 78 | func (s *Script) Send(c Conn, keysAndArgs ...interface{}) error { 79 | return c.Send("EVAL", s.args(s.src, keysAndArgs)...) 80 | } 81 | 82 | // Load loads the script without evaluating it. 83 | func (s *Script) Load(c Conn) error { 84 | _, err := c.Do("SCRIPT", "LOAD", s.src) 85 | return err 86 | } 87 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/.gitignore: -------------------------------------------------------------------------------- 1 | /lib 2 | /jemalloc 3 | /VERSION 4 | 5 | je_*.c 6 | *.swp 7 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | os: 4 | - linux 5 | - osx 6 | 7 | go: 8 | - 1.8.x 9 | - 1.7.x 10 | - 1.6.x 11 | 12 | script: 13 | - make install 14 | - make test 15 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/Makefile: -------------------------------------------------------------------------------- 1 | .DEFAULT_GOAL = build 2 | 3 | PWD := $(shell pwd) 4 | SRC := jemalloc-4.5.0 5 | 6 | build: 7 | @test -f $(SRC)/Makefile || make config --quiet 8 | 9 | install: build 10 | @go install -x -v ./ 11 | 12 | config: 13 | @cd $(SRC) && ./autogen.sh --with-jemalloc-prefix="je_" 14 | @rm -rf jemalloc VERSION 15 | @ln -s $(SRC)/include/jemalloc 16 | @ln -s $(SRC)/VERSION 17 | @make -f help.mk relink 18 | 19 | clean distclean: 20 | @test -f $(SRC)/Makefile && make -C $(SRC) --quiet distclean || true 21 | @rm -rf jemalloc VERSION 22 | @make -f help.mk unlink 23 | 24 | relink unlink: 25 | @make -f help.mk $@ 26 | 27 | test: 28 | @go test -v ./ 29 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/README.md: -------------------------------------------------------------------------------- 1 | # jemalloc 2 | [![Build Status](https://travis-ci.org/spinlock/jemalloc-go.svg)](https://travis-ci.org/spinlock/jemalloc-go) 3 | 4 | #### How to setup & install 5 | ```bash 6 | $ mkdir -p $GOPATH/src/github.com/spinlock 7 | $ cd $_ 8 | $ git clone https://github.com/spinlock/jemalloc-go.git 9 | $ cd jemalloc-go 10 | $ make install 11 | ``` 12 | 13 | #### How to use it 14 | 15 | ```go 16 | package demo 17 | 18 | // #cgo CPPFLAGS: -I/jemalloc-go 19 | // #cgo darwin LDFLAGS: -Wl,-undefined -Wl,dynamic_lookup 20 | // #cgo !darwin LDFLAGS: -Wl,-unresolved-symbols=ignore-all 21 | // #include 22 | import "C" 23 | 24 | import jemalloc "github.com/spinlock/jemalloc-go" 25 | 26 | func malloc1(n int) unsafe.Pointer { 27 | return C.je_malloc(C.size_t(n)) 28 | } 29 | 30 | func free1(p unsafe.Pointer) { 31 | C.je_free(p) 32 | } 33 | 34 | func malloc2(n int) unsafe.Pointer { 35 | return jemalloc.Malloc(n) 36 | } 37 | 38 | func free2(p unsafe.Pointer) { 39 | jemalloc.Free(p) 40 | } 41 | ``` 42 | 43 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/VERSION: -------------------------------------------------------------------------------- 1 | jemalloc-4.5.0/VERSION -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/help.mk: -------------------------------------------------------------------------------- 1 | .DEFAULT_GOAL = relink 2 | 3 | PWD := $(shell pwd) 4 | SRC := jemalloc-4.5.0 5 | 6 | -include $(SRC)/Makefile 7 | 8 | relink: unlink 9 | @for i in $(C_SRCS); do \ 10 | rm -f je_$$(basename $$i); \ 11 | ln -s $(SRC)/$$i je_$$(basename $$i); \ 12 | done 13 | 14 | unlink: 15 | @rm -f je_*.c 16 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/je_arena.c: -------------------------------------------------------------------------------- 1 | jemalloc-4.5.0/src/arena.c -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/je_atomic.c: -------------------------------------------------------------------------------- 1 | jemalloc-4.5.0/src/atomic.c -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/je_base.c: -------------------------------------------------------------------------------- 1 | jemalloc-4.5.0/src/base.c -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/je_bitmap.c: -------------------------------------------------------------------------------- 1 | jemalloc-4.5.0/src/bitmap.c -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/je_chunk.c: -------------------------------------------------------------------------------- 1 | jemalloc-4.5.0/src/chunk.c -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/je_chunk_dss.c: -------------------------------------------------------------------------------- 1 | jemalloc-4.5.0/src/chunk_dss.c -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/je_chunk_mmap.c: -------------------------------------------------------------------------------- 1 | jemalloc-4.5.0/src/chunk_mmap.c -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/je_ckh.c: -------------------------------------------------------------------------------- 1 | jemalloc-4.5.0/src/ckh.c -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/je_ctl.c: -------------------------------------------------------------------------------- 1 | jemalloc-4.5.0/src/ctl.c -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/je_extent.c: -------------------------------------------------------------------------------- 1 | jemalloc-4.5.0/src/extent.c -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/je_hash.c: -------------------------------------------------------------------------------- 1 | jemalloc-4.5.0/src/hash.c -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/je_huge.c: -------------------------------------------------------------------------------- 1 | jemalloc-4.5.0/src/huge.c -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/je_jemalloc.c: -------------------------------------------------------------------------------- 1 | jemalloc-4.5.0/src/jemalloc.c -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/je_mb.c: -------------------------------------------------------------------------------- 1 | jemalloc-4.5.0/src/mb.c -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/je_mutex.c: -------------------------------------------------------------------------------- 1 | jemalloc-4.5.0/src/mutex.c -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/je_nstime.c: -------------------------------------------------------------------------------- 1 | jemalloc-4.5.0/src/nstime.c -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/je_pages.c: -------------------------------------------------------------------------------- 1 | jemalloc-4.5.0/src/pages.c -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/je_prng.c: -------------------------------------------------------------------------------- 1 | jemalloc-4.5.0/src/prng.c -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/je_prof.c: -------------------------------------------------------------------------------- 1 | jemalloc-4.5.0/src/prof.c -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/je_quarantine.c: -------------------------------------------------------------------------------- 1 | jemalloc-4.5.0/src/quarantine.c -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/je_rtree.c: -------------------------------------------------------------------------------- 1 | jemalloc-4.5.0/src/rtree.c -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/je_spin.c: -------------------------------------------------------------------------------- 1 | jemalloc-4.5.0/src/spin.c -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/je_stats.c: -------------------------------------------------------------------------------- 1 | jemalloc-4.5.0/src/stats.c -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/je_tcache.c: -------------------------------------------------------------------------------- 1 | jemalloc-4.5.0/src/tcache.c -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/je_ticker.c: -------------------------------------------------------------------------------- 1 | jemalloc-4.5.0/src/ticker.c -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/je_tsd.c: -------------------------------------------------------------------------------- 1 | jemalloc-4.5.0/src/tsd.c -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/je_util.c: -------------------------------------------------------------------------------- 1 | jemalloc-4.5.0/src/util.c -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/je_valgrind.c: -------------------------------------------------------------------------------- 1 | jemalloc-4.5.0/src/valgrind.c -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/je_witness.c: -------------------------------------------------------------------------------- 1 | jemalloc-4.5.0/src/witness.c -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc: -------------------------------------------------------------------------------- 1 | jemalloc-4.5.0/include/jemalloc -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/.appveyor.yml: -------------------------------------------------------------------------------- 1 | version: '{build}' 2 | 3 | environment: 4 | matrix: 5 | - MSYSTEM: MINGW64 6 | CPU: x86_64 7 | MSVC: amd64 8 | - MSYSTEM: MINGW32 9 | CPU: i686 10 | MSVC: x86 11 | - MSYSTEM: MINGW64 12 | CPU: x86_64 13 | - MSYSTEM: MINGW32 14 | CPU: i686 15 | - MSYSTEM: MINGW64 16 | CPU: x86_64 17 | MSVC: amd64 18 | CONFIG_FLAGS: --enable-debug 19 | - MSYSTEM: MINGW32 20 | CPU: i686 21 | MSVC: x86 22 | CONFIG_FLAGS: --enable-debug 23 | - MSYSTEM: MINGW64 24 | CPU: x86_64 25 | CONFIG_FLAGS: --enable-debug 26 | - MSYSTEM: MINGW32 27 | CPU: i686 28 | CONFIG_FLAGS: --enable-debug 29 | 30 | install: 31 | - set PATH=c:\msys64\%MSYSTEM%\bin;c:\msys64\usr\bin;%PATH% 32 | - if defined MSVC call "c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" %MSVC% 33 | - if defined MSVC pacman --noconfirm -Rsc mingw-w64-%CPU%-gcc gcc 34 | - pacman --noconfirm -Suy mingw-w64-%CPU%-make 35 | 36 | build_script: 37 | - bash -c "autoconf" 38 | - bash -c "./configure $CONFIG_FLAGS" 39 | - mingw32-make -j3 40 | - file lib/jemalloc.dll 41 | - mingw32-make -j3 tests 42 | - mingw32-make -k check 43 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/.autom4te.cfg: -------------------------------------------------------------------------------- 1 | begin-language: "Autoconf-without-aclocal-m4" 2 | args: --no-cache 3 | end-language: "Autoconf-without-aclocal-m4" 4 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/.gitignore: -------------------------------------------------------------------------------- 1 | /*.gcov.* 2 | 3 | /bin/jemalloc-config 4 | /bin/jemalloc.sh 5 | /bin/jeprof 6 | 7 | /config.stamp 8 | /config.log 9 | /config.status 10 | /configure 11 | 12 | /doc/html.xsl 13 | /doc/manpages.xsl 14 | /doc/jemalloc.xml 15 | /doc/jemalloc.html 16 | /doc/jemalloc.3 17 | 18 | /jemalloc.pc 19 | 20 | /lib/ 21 | 22 | /Makefile 23 | 24 | /include/jemalloc/internal/jemalloc_internal.h 25 | /include/jemalloc/internal/jemalloc_internal_defs.h 26 | /include/jemalloc/internal/private_namespace.h 27 | /include/jemalloc/internal/private_unnamespace.h 28 | /include/jemalloc/internal/public_namespace.h 29 | /include/jemalloc/internal/public_symbols.txt 30 | /include/jemalloc/internal/public_unnamespace.h 31 | /include/jemalloc/internal/size_classes.h 32 | /include/jemalloc/jemalloc.h 33 | /include/jemalloc/jemalloc_defs.h 34 | /include/jemalloc/jemalloc_macros.h 35 | /include/jemalloc/jemalloc_mangle.h 36 | /include/jemalloc/jemalloc_mangle_jet.h 37 | /include/jemalloc/jemalloc_protos.h 38 | /include/jemalloc/jemalloc_protos_jet.h 39 | /include/jemalloc/jemalloc_rename.h 40 | /include/jemalloc/jemalloc_typedefs.h 41 | 42 | /src/*.[od] 43 | /src/*.gcda 44 | /src/*.gcno 45 | 46 | /test/test.sh 47 | test/include/test/jemalloc_test.h 48 | test/include/test/jemalloc_test_defs.h 49 | 50 | /test/integration/[A-Za-z]* 51 | !/test/integration/[A-Za-z]*.* 52 | /test/integration/*.[od] 53 | /test/integration/*.gcda 54 | /test/integration/*.gcno 55 | /test/integration/*.out 56 | 57 | /test/src/*.[od] 58 | /test/src/*.gcda 59 | /test/src/*.gcno 60 | 61 | /test/stress/[A-Za-z]* 62 | !/test/stress/[A-Za-z]*.* 63 | /test/stress/*.[od] 64 | /test/stress/*.gcda 65 | /test/stress/*.gcno 66 | /test/stress/*.out 67 | 68 | /test/unit/[A-Za-z]* 69 | !/test/unit/[A-Za-z]*.* 70 | /test/unit/*.[od] 71 | /test/unit/*.gcda 72 | /test/unit/*.gcno 73 | /test/unit/*.out 74 | 75 | /VERSION 76 | 77 | *.pdb 78 | *.sdf 79 | *.opendb 80 | *.opensdf 81 | *.cachefile 82 | *.suo 83 | *.user 84 | *.sln.docstates 85 | *.tmp 86 | /msvc/Win32/ 87 | /msvc/x64/ 88 | /msvc/projects/*/*/Debug*/ 89 | /msvc/projects/*/*/Release*/ 90 | /msvc/projects/*/*/Win32/ 91 | /msvc/projects/*/*/x64/ 92 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/COPYING: -------------------------------------------------------------------------------- 1 | Unless otherwise specified, files in the jemalloc source distribution are 2 | subject to the following license: 3 | -------------------------------------------------------------------------------- 4 | Copyright (C) 2002-2016 Jason Evans . 5 | All rights reserved. 6 | Copyright (C) 2007-2012 Mozilla Foundation. All rights reserved. 7 | Copyright (C) 2009-2016 Facebook, Inc. All rights reserved. 8 | 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions are met: 11 | 1. Redistributions of source code must retain the above copyright notice(s), 12 | this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright notice(s), 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS 18 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 20 | EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 25 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- 28 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/README: -------------------------------------------------------------------------------- 1 | jemalloc is a general purpose malloc(3) implementation that emphasizes 2 | fragmentation avoidance and scalable concurrency support. jemalloc first came 3 | into use as the FreeBSD libc allocator in 2005, and since then it has found its 4 | way into numerous applications that rely on its predictable behavior. In 2010 5 | jemalloc development efforts broadened to include developer support features 6 | such as heap profiling, Valgrind integration, and extensive monitoring/tuning 7 | hooks. Modern jemalloc releases continue to be integrated back into FreeBSD, 8 | and therefore versatility remains critical. Ongoing development efforts trend 9 | toward making jemalloc among the best allocators for a broad range of demanding 10 | applications, and eliminating/mitigating weaknesses that have practical 11 | repercussions for real world applications. 12 | 13 | The COPYING file contains copyright and licensing information. 14 | 15 | The INSTALL file contains information on how to configure, build, and install 16 | jemalloc. 17 | 18 | The ChangeLog file contains a brief summary of changes for each release. 19 | 20 | URL: http://jemalloc.net/ 21 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | for i in autoconf; do 4 | echo "$i" 5 | $i 6 | if [ $? -ne 0 ]; then 7 | echo "Error $? in $i" 8 | exit 1 9 | fi 10 | done 11 | 12 | echo "./configure --enable-autogen $@" 13 | ./configure --enable-autogen $@ 14 | if [ $? -ne 0 ]; then 15 | echo "Error $? in ./configure" 16 | exit 1 17 | fi 18 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/bin/jemalloc-config.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | usage() { 4 | cat < 7 | Options: 8 | --help | -h : Print usage. 9 | --version : Print jemalloc version. 10 | --revision : Print shared library revision number. 11 | --config : Print configure options used to build jemalloc. 12 | --prefix : Print installation directory prefix. 13 | --bindir : Print binary installation directory. 14 | --datadir : Print data installation directory. 15 | --includedir : Print include installation directory. 16 | --libdir : Print library installation directory. 17 | --mandir : Print manual page installation directory. 18 | --cc : Print compiler used to build jemalloc. 19 | --cflags : Print compiler flags used to build jemalloc. 20 | --cppflags : Print preprocessor flags used to build jemalloc. 21 | --ldflags : Print library flags used to build jemalloc. 22 | --libs : Print libraries jemalloc was linked against. 23 | EOF 24 | } 25 | 26 | prefix="@prefix@" 27 | exec_prefix="@exec_prefix@" 28 | 29 | case "$1" in 30 | --help | -h) 31 | usage 32 | exit 0 33 | ;; 34 | --version) 35 | echo "@jemalloc_version@" 36 | ;; 37 | --revision) 38 | echo "@rev@" 39 | ;; 40 | --config) 41 | echo "@CONFIG@" 42 | ;; 43 | --prefix) 44 | echo "@PREFIX@" 45 | ;; 46 | --bindir) 47 | echo "@BINDIR@" 48 | ;; 49 | --datadir) 50 | echo "@DATADIR@" 51 | ;; 52 | --includedir) 53 | echo "@INCLUDEDIR@" 54 | ;; 55 | --libdir) 56 | echo "@LIBDIR@" 57 | ;; 58 | --mandir) 59 | echo "@MANDIR@" 60 | ;; 61 | --cc) 62 | echo "@CC@" 63 | ;; 64 | --cflags) 65 | echo "@CFLAGS@" 66 | ;; 67 | --cppflags) 68 | echo "@CPPFLAGS@" 69 | ;; 70 | --ldflags) 71 | echo "@LDFLAGS@ @EXTRA_LDFLAGS@" 72 | ;; 73 | --libs) 74 | echo "@LIBS@" 75 | ;; 76 | *) 77 | usage 78 | exit 1 79 | esac 80 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/bin/jemalloc.sh.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | prefix=@prefix@ 4 | exec_prefix=@exec_prefix@ 5 | libdir=@libdir@ 6 | 7 | @LD_PRELOAD_VAR@=${libdir}/libjemalloc.@SOREV@ 8 | export @LD_PRELOAD_VAR@ 9 | exec "$@" 10 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/config.stamp.in: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodisLabs/redis-port/a2e08c1edc05bdb7a2ad0ae29369f405f77eeaa1/vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/config.stamp.in -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/coverage.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | objdir=$1 6 | suffix=$2 7 | shift 2 8 | objs=$@ 9 | 10 | gcov -b -p -f -o "${objdir}" ${objs} 11 | 12 | # Move gcov outputs so that subsequent gcov invocations won't clobber results 13 | # for the same sources with different compilation flags. 14 | for f in `find . -maxdepth 1 -type f -name '*.gcov'` ; do 15 | mv "${f}" "${f}.${suffix}" 16 | done 17 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/doc/html.xsl.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/doc/manpages.xsl.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/doc/stylesheet.xsl: -------------------------------------------------------------------------------- 1 | 2 | ansi 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/include/jemalloc/internal/assert.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Define a custom assert() in order to reduce the chances of deadlock during 3 | * assertion failure. 4 | */ 5 | #ifndef assert 6 | #define assert(e) do { \ 7 | if (unlikely(config_debug && !(e))) { \ 8 | malloc_printf( \ 9 | ": %s:%d: Failed assertion: \"%s\"\n", \ 10 | __FILE__, __LINE__, #e); \ 11 | abort(); \ 12 | } \ 13 | } while (0) 14 | #endif 15 | 16 | #ifndef not_reached 17 | #define not_reached() do { \ 18 | if (config_debug) { \ 19 | malloc_printf( \ 20 | ": %s:%d: Unreachable code reached\n", \ 21 | __FILE__, __LINE__); \ 22 | abort(); \ 23 | } \ 24 | unreachable(); \ 25 | } while (0) 26 | #endif 27 | 28 | #ifndef not_implemented 29 | #define not_implemented() do { \ 30 | if (config_debug) { \ 31 | malloc_printf(": %s:%d: Not implemented\n", \ 32 | __FILE__, __LINE__); \ 33 | abort(); \ 34 | } \ 35 | } while (0) 36 | #endif 37 | 38 | #ifndef assert_not_implemented 39 | #define assert_not_implemented(e) do { \ 40 | if (unlikely(config_debug && !(e))) \ 41 | not_implemented(); \ 42 | } while (0) 43 | #endif 44 | 45 | 46 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/include/jemalloc/internal/base.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | #ifdef JEMALLOC_H_TYPES 3 | 4 | #endif /* JEMALLOC_H_TYPES */ 5 | /******************************************************************************/ 6 | #ifdef JEMALLOC_H_STRUCTS 7 | 8 | #endif /* JEMALLOC_H_STRUCTS */ 9 | /******************************************************************************/ 10 | #ifdef JEMALLOC_H_EXTERNS 11 | 12 | void *base_alloc(tsdn_t *tsdn, size_t size); 13 | void base_stats_get(tsdn_t *tsdn, size_t *allocated, size_t *resident, 14 | size_t *mapped); 15 | bool base_boot(void); 16 | void base_prefork(tsdn_t *tsdn); 17 | void base_postfork_parent(tsdn_t *tsdn); 18 | void base_postfork_child(tsdn_t *tsdn); 19 | 20 | #endif /* JEMALLOC_H_EXTERNS */ 21 | /******************************************************************************/ 22 | #ifdef JEMALLOC_H_INLINES 23 | 24 | #endif /* JEMALLOC_H_INLINES */ 25 | /******************************************************************************/ 26 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/include/jemalloc/internal/chunk_dss.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | #ifdef JEMALLOC_H_TYPES 3 | 4 | typedef enum { 5 | dss_prec_disabled = 0, 6 | dss_prec_primary = 1, 7 | dss_prec_secondary = 2, 8 | 9 | dss_prec_limit = 3 10 | } dss_prec_t; 11 | #define DSS_PREC_DEFAULT dss_prec_secondary 12 | #define DSS_DEFAULT "secondary" 13 | 14 | #endif /* JEMALLOC_H_TYPES */ 15 | /******************************************************************************/ 16 | #ifdef JEMALLOC_H_STRUCTS 17 | 18 | extern const char *dss_prec_names[]; 19 | 20 | #endif /* JEMALLOC_H_STRUCTS */ 21 | /******************************************************************************/ 22 | #ifdef JEMALLOC_H_EXTERNS 23 | 24 | dss_prec_t chunk_dss_prec_get(void); 25 | bool chunk_dss_prec_set(dss_prec_t dss_prec); 26 | void *chunk_alloc_dss(tsdn_t *tsdn, arena_t *arena, void *new_addr, 27 | size_t size, size_t alignment, bool *zero, bool *commit); 28 | bool chunk_in_dss(void *chunk); 29 | bool chunk_dss_mergeable(void *chunk_a, void *chunk_b); 30 | void chunk_dss_boot(void); 31 | 32 | #endif /* JEMALLOC_H_EXTERNS */ 33 | /******************************************************************************/ 34 | #ifdef JEMALLOC_H_INLINES 35 | 36 | #endif /* JEMALLOC_H_INLINES */ 37 | /******************************************************************************/ 38 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/include/jemalloc/internal/chunk_mmap.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | #ifdef JEMALLOC_H_TYPES 3 | 4 | #endif /* JEMALLOC_H_TYPES */ 5 | /******************************************************************************/ 6 | #ifdef JEMALLOC_H_STRUCTS 7 | 8 | #endif /* JEMALLOC_H_STRUCTS */ 9 | /******************************************************************************/ 10 | #ifdef JEMALLOC_H_EXTERNS 11 | 12 | void *chunk_alloc_mmap(void *new_addr, size_t size, size_t alignment, 13 | bool *zero, bool *commit); 14 | bool chunk_dalloc_mmap(void *chunk, size_t size); 15 | 16 | #endif /* JEMALLOC_H_EXTERNS */ 17 | /******************************************************************************/ 18 | #ifdef JEMALLOC_H_INLINES 19 | 20 | #endif /* JEMALLOC_H_INLINES */ 21 | /******************************************************************************/ 22 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/include/jemalloc/internal/ckh.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | #ifdef JEMALLOC_H_TYPES 3 | 4 | typedef struct ckh_s ckh_t; 5 | typedef struct ckhc_s ckhc_t; 6 | 7 | /* Typedefs to allow easy function pointer passing. */ 8 | typedef void ckh_hash_t (const void *, size_t[2]); 9 | typedef bool ckh_keycomp_t (const void *, const void *); 10 | 11 | /* Maintain counters used to get an idea of performance. */ 12 | /* #define CKH_COUNT */ 13 | /* Print counter values in ckh_delete() (requires CKH_COUNT). */ 14 | /* #define CKH_VERBOSE */ 15 | 16 | /* 17 | * There are 2^LG_CKH_BUCKET_CELLS cells in each hash table bucket. Try to fit 18 | * one bucket per L1 cache line. 19 | */ 20 | #define LG_CKH_BUCKET_CELLS (LG_CACHELINE - LG_SIZEOF_PTR - 1) 21 | 22 | #endif /* JEMALLOC_H_TYPES */ 23 | /******************************************************************************/ 24 | #ifdef JEMALLOC_H_STRUCTS 25 | 26 | /* Hash table cell. */ 27 | struct ckhc_s { 28 | const void *key; 29 | const void *data; 30 | }; 31 | 32 | struct ckh_s { 33 | #ifdef CKH_COUNT 34 | /* Counters used to get an idea of performance. */ 35 | uint64_t ngrows; 36 | uint64_t nshrinks; 37 | uint64_t nshrinkfails; 38 | uint64_t ninserts; 39 | uint64_t nrelocs; 40 | #endif 41 | 42 | /* Used for pseudo-random number generation. */ 43 | uint64_t prng_state; 44 | 45 | /* Total number of items. */ 46 | size_t count; 47 | 48 | /* 49 | * Minimum and current number of hash table buckets. There are 50 | * 2^LG_CKH_BUCKET_CELLS cells per bucket. 51 | */ 52 | unsigned lg_minbuckets; 53 | unsigned lg_curbuckets; 54 | 55 | /* Hash and comparison functions. */ 56 | ckh_hash_t *hash; 57 | ckh_keycomp_t *keycomp; 58 | 59 | /* Hash table with 2^lg_curbuckets buckets. */ 60 | ckhc_t *tab; 61 | }; 62 | 63 | #endif /* JEMALLOC_H_STRUCTS */ 64 | /******************************************************************************/ 65 | #ifdef JEMALLOC_H_EXTERNS 66 | 67 | bool ckh_new(tsd_t *tsd, ckh_t *ckh, size_t minitems, ckh_hash_t *hash, 68 | ckh_keycomp_t *keycomp); 69 | void ckh_delete(tsd_t *tsd, ckh_t *ckh); 70 | size_t ckh_count(ckh_t *ckh); 71 | bool ckh_iter(ckh_t *ckh, size_t *tabind, void **key, void **data); 72 | bool ckh_insert(tsd_t *tsd, ckh_t *ckh, const void *key, const void *data); 73 | bool ckh_remove(tsd_t *tsd, ckh_t *ckh, const void *searchkey, void **key, 74 | void **data); 75 | bool ckh_search(ckh_t *ckh, const void *searchkey, void **key, void **data); 76 | void ckh_string_hash(const void *key, size_t r_hash[2]); 77 | bool ckh_string_keycomp(const void *k1, const void *k2); 78 | void ckh_pointer_hash(const void *key, size_t r_hash[2]); 79 | bool ckh_pointer_keycomp(const void *k1, const void *k2); 80 | 81 | #endif /* JEMALLOC_H_EXTERNS */ 82 | /******************************************************************************/ 83 | #ifdef JEMALLOC_H_INLINES 84 | 85 | #endif /* JEMALLOC_H_INLINES */ 86 | /******************************************************************************/ 87 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/include/jemalloc/internal/huge.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | #ifdef JEMALLOC_H_TYPES 3 | 4 | #endif /* JEMALLOC_H_TYPES */ 5 | /******************************************************************************/ 6 | #ifdef JEMALLOC_H_STRUCTS 7 | 8 | #endif /* JEMALLOC_H_STRUCTS */ 9 | /******************************************************************************/ 10 | #ifdef JEMALLOC_H_EXTERNS 11 | 12 | void *huge_malloc(tsdn_t *tsdn, arena_t *arena, size_t usize, bool zero); 13 | void *huge_palloc(tsdn_t *tsdn, arena_t *arena, size_t usize, 14 | size_t alignment, bool zero); 15 | bool huge_ralloc_no_move(tsdn_t *tsdn, void *ptr, size_t oldsize, 16 | size_t usize_min, size_t usize_max, bool zero); 17 | void *huge_ralloc(tsd_t *tsd, arena_t *arena, void *ptr, size_t oldsize, 18 | size_t usize, size_t alignment, bool zero, tcache_t *tcache); 19 | #ifdef JEMALLOC_JET 20 | typedef void (huge_dalloc_junk_t)(void *, size_t); 21 | extern huge_dalloc_junk_t *huge_dalloc_junk; 22 | #endif 23 | void huge_dalloc(tsdn_t *tsdn, void *ptr); 24 | arena_t *huge_aalloc(const void *ptr); 25 | size_t huge_salloc(tsdn_t *tsdn, const void *ptr); 26 | prof_tctx_t *huge_prof_tctx_get(tsdn_t *tsdn, const void *ptr); 27 | void huge_prof_tctx_set(tsdn_t *tsdn, const void *ptr, prof_tctx_t *tctx); 28 | void huge_prof_tctx_reset(tsdn_t *tsdn, const void *ptr); 29 | 30 | #endif /* JEMALLOC_H_EXTERNS */ 31 | /******************************************************************************/ 32 | #ifdef JEMALLOC_H_INLINES 33 | 34 | #endif /* JEMALLOC_H_INLINES */ 35 | /******************************************************************************/ 36 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/include/jemalloc/internal/jemalloc_internal_decls.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_DECLS_H 2 | #define JEMALLOC_INTERNAL_DECLS_H 3 | 4 | #include 5 | #ifdef _WIN32 6 | # include 7 | # include "msvc_compat/windows_extra.h" 8 | 9 | #else 10 | # include 11 | # include 12 | # if !defined(__pnacl__) && !defined(__native_client__) 13 | # include 14 | # if !defined(SYS_write) && defined(__NR_write) 15 | # define SYS_write __NR_write 16 | # endif 17 | # include 18 | # endif 19 | # include 20 | # ifdef JEMALLOC_OS_UNFAIR_LOCK 21 | # include 22 | # endif 23 | # ifdef JEMALLOC_GLIBC_MALLOC_HOOK 24 | # include 25 | # endif 26 | # include 27 | # include 28 | # include 29 | # ifdef JEMALLOC_HAVE_MACH_ABSOLUTE_TIME 30 | # include 31 | # endif 32 | #endif 33 | #include 34 | 35 | #include 36 | #ifndef SIZE_T_MAX 37 | # define SIZE_T_MAX SIZE_MAX 38 | #endif 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #ifndef offsetof 46 | # define offsetof(type, member) ((size_t)&(((type *)NULL)->member)) 47 | #endif 48 | #include 49 | #include 50 | #include 51 | #ifdef _MSC_VER 52 | # include 53 | typedef intptr_t ssize_t; 54 | # define PATH_MAX 1024 55 | # define STDERR_FILENO 2 56 | # define __func__ __FUNCTION__ 57 | # ifdef JEMALLOC_HAS_RESTRICT 58 | # define restrict __restrict 59 | # endif 60 | /* Disable warnings about deprecated system functions. */ 61 | # pragma warning(disable: 4996) 62 | #if _MSC_VER < 1800 63 | static int 64 | isblank(int c) 65 | { 66 | 67 | return (c == '\t' || c == ' '); 68 | } 69 | #endif 70 | #else 71 | # include 72 | #endif 73 | #include 74 | 75 | #endif /* JEMALLOC_INTERNAL_H */ 76 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/include/jemalloc/internal/jemalloc_internal_macros.h: -------------------------------------------------------------------------------- 1 | /* 2 | * JEMALLOC_ALWAYS_INLINE and JEMALLOC_INLINE are used within header files for 3 | * functions that are static inline functions if inlining is enabled, and 4 | * single-definition library-private functions if inlining is disabled. 5 | * 6 | * JEMALLOC_ALWAYS_INLINE_C and JEMALLOC_INLINE_C are for use in .c files, in 7 | * which case the denoted functions are always static, regardless of whether 8 | * inlining is enabled. 9 | */ 10 | #if defined(JEMALLOC_DEBUG) || defined(JEMALLOC_CODE_COVERAGE) 11 | /* Disable inlining to make debugging/profiling easier. */ 12 | # define JEMALLOC_ALWAYS_INLINE 13 | # define JEMALLOC_ALWAYS_INLINE_C static 14 | # define JEMALLOC_INLINE 15 | # define JEMALLOC_INLINE_C static 16 | # define inline 17 | #else 18 | # define JEMALLOC_ENABLE_INLINE 19 | # ifdef JEMALLOC_HAVE_ATTR 20 | # define JEMALLOC_ALWAYS_INLINE \ 21 | static inline JEMALLOC_ATTR(unused) JEMALLOC_ATTR(always_inline) 22 | # define JEMALLOC_ALWAYS_INLINE_C \ 23 | static inline JEMALLOC_ATTR(always_inline) 24 | # else 25 | # define JEMALLOC_ALWAYS_INLINE static inline 26 | # define JEMALLOC_ALWAYS_INLINE_C static inline 27 | # endif 28 | # define JEMALLOC_INLINE static inline 29 | # define JEMALLOC_INLINE_C static inline 30 | # ifdef _MSC_VER 31 | # define inline _inline 32 | # endif 33 | #endif 34 | 35 | #ifdef JEMALLOC_CC_SILENCE 36 | # define UNUSED JEMALLOC_ATTR(unused) 37 | #else 38 | # define UNUSED 39 | #endif 40 | 41 | #define ZU(z) ((size_t)z) 42 | #define ZI(z) ((ssize_t)z) 43 | #define QU(q) ((uint64_t)q) 44 | #define QI(q) ((int64_t)q) 45 | 46 | #define KZU(z) ZU(z##ULL) 47 | #define KZI(z) ZI(z##LL) 48 | #define KQU(q) QU(q##ULL) 49 | #define KQI(q) QI(q##LL) 50 | 51 | #ifndef __DECONST 52 | # define __DECONST(type, var) ((type)(uintptr_t)(const void *)(var)) 53 | #endif 54 | 55 | #ifndef JEMALLOC_HAS_RESTRICT 56 | # define restrict 57 | #endif 58 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/include/jemalloc/internal/nstime.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | #ifdef JEMALLOC_H_TYPES 3 | 4 | typedef struct nstime_s nstime_t; 5 | 6 | /* Maximum supported number of seconds (~584 years). */ 7 | #define NSTIME_SEC_MAX KQU(18446744072) 8 | 9 | #endif /* JEMALLOC_H_TYPES */ 10 | /******************************************************************************/ 11 | #ifdef JEMALLOC_H_STRUCTS 12 | 13 | struct nstime_s { 14 | uint64_t ns; 15 | }; 16 | 17 | #endif /* JEMALLOC_H_STRUCTS */ 18 | /******************************************************************************/ 19 | #ifdef JEMALLOC_H_EXTERNS 20 | 21 | void nstime_init(nstime_t *time, uint64_t ns); 22 | void nstime_init2(nstime_t *time, uint64_t sec, uint64_t nsec); 23 | uint64_t nstime_ns(const nstime_t *time); 24 | uint64_t nstime_sec(const nstime_t *time); 25 | uint64_t nstime_nsec(const nstime_t *time); 26 | void nstime_copy(nstime_t *time, const nstime_t *source); 27 | int nstime_compare(const nstime_t *a, const nstime_t *b); 28 | void nstime_add(nstime_t *time, const nstime_t *addend); 29 | void nstime_subtract(nstime_t *time, const nstime_t *subtrahend); 30 | void nstime_imultiply(nstime_t *time, uint64_t multiplier); 31 | void nstime_idivide(nstime_t *time, uint64_t divisor); 32 | uint64_t nstime_divide(const nstime_t *time, const nstime_t *divisor); 33 | #ifdef JEMALLOC_JET 34 | typedef bool (nstime_monotonic_t)(void); 35 | extern nstime_monotonic_t *nstime_monotonic; 36 | typedef bool (nstime_update_t)(nstime_t *); 37 | extern nstime_update_t *nstime_update; 38 | #else 39 | bool nstime_monotonic(void); 40 | bool nstime_update(nstime_t *time); 41 | #endif 42 | 43 | #endif /* JEMALLOC_H_EXTERNS */ 44 | /******************************************************************************/ 45 | #ifdef JEMALLOC_H_INLINES 46 | 47 | #endif /* JEMALLOC_H_INLINES */ 48 | /******************************************************************************/ 49 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/include/jemalloc/internal/pages.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | #ifdef JEMALLOC_H_TYPES 3 | 4 | #endif /* JEMALLOC_H_TYPES */ 5 | /******************************************************************************/ 6 | #ifdef JEMALLOC_H_STRUCTS 7 | 8 | #endif /* JEMALLOC_H_STRUCTS */ 9 | /******************************************************************************/ 10 | #ifdef JEMALLOC_H_EXTERNS 11 | 12 | void *pages_map(void *addr, size_t size, bool *commit); 13 | void pages_unmap(void *addr, size_t size); 14 | void *pages_trim(void *addr, size_t alloc_size, size_t leadsize, 15 | size_t size, bool *commit); 16 | bool pages_commit(void *addr, size_t size); 17 | bool pages_decommit(void *addr, size_t size); 18 | bool pages_purge(void *addr, size_t size); 19 | bool pages_huge(void *addr, size_t size); 20 | bool pages_nohuge(void *addr, size_t size); 21 | void pages_boot(void); 22 | 23 | #endif /* JEMALLOC_H_EXTERNS */ 24 | /******************************************************************************/ 25 | #ifdef JEMALLOC_H_INLINES 26 | 27 | #endif /* JEMALLOC_H_INLINES */ 28 | /******************************************************************************/ 29 | 30 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/include/jemalloc/internal/private_namespace.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | for symbol in `cat $1` ; do 4 | echo "#define ${symbol} JEMALLOC_N(${symbol})" 5 | done 6 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/include/jemalloc/internal/private_unnamespace.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | for symbol in `cat $1` ; do 4 | echo "#undef ${symbol}" 5 | done 6 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/include/jemalloc/internal/public_namespace.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | for nm in `cat $1` ; do 4 | n=`echo ${nm} |tr ':' ' ' |awk '{print $1}'` 5 | echo "#define je_${n} JEMALLOC_N(${n})" 6 | done 7 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/include/jemalloc/internal/public_unnamespace.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | for nm in `cat $1` ; do 4 | n=`echo ${nm} |tr ':' ' ' |awk '{print $1}'` 5 | echo "#undef je_${n}" 6 | done 7 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/include/jemalloc/internal/ql.h: -------------------------------------------------------------------------------- 1 | /* List definitions. */ 2 | #define ql_head(a_type) \ 3 | struct { \ 4 | a_type *qlh_first; \ 5 | } 6 | 7 | #define ql_head_initializer(a_head) {NULL} 8 | 9 | #define ql_elm(a_type) qr(a_type) 10 | 11 | /* List functions. */ 12 | #define ql_new(a_head) do { \ 13 | (a_head)->qlh_first = NULL; \ 14 | } while (0) 15 | 16 | #define ql_elm_new(a_elm, a_field) qr_new((a_elm), a_field) 17 | 18 | #define ql_first(a_head) ((a_head)->qlh_first) 19 | 20 | #define ql_last(a_head, a_field) \ 21 | ((ql_first(a_head) != NULL) \ 22 | ? qr_prev(ql_first(a_head), a_field) : NULL) 23 | 24 | #define ql_next(a_head, a_elm, a_field) \ 25 | ((ql_last(a_head, a_field) != (a_elm)) \ 26 | ? qr_next((a_elm), a_field) : NULL) 27 | 28 | #define ql_prev(a_head, a_elm, a_field) \ 29 | ((ql_first(a_head) != (a_elm)) ? qr_prev((a_elm), a_field) \ 30 | : NULL) 31 | 32 | #define ql_before_insert(a_head, a_qlelm, a_elm, a_field) do { \ 33 | qr_before_insert((a_qlelm), (a_elm), a_field); \ 34 | if (ql_first(a_head) == (a_qlelm)) { \ 35 | ql_first(a_head) = (a_elm); \ 36 | } \ 37 | } while (0) 38 | 39 | #define ql_after_insert(a_qlelm, a_elm, a_field) \ 40 | qr_after_insert((a_qlelm), (a_elm), a_field) 41 | 42 | #define ql_head_insert(a_head, a_elm, a_field) do { \ 43 | if (ql_first(a_head) != NULL) { \ 44 | qr_before_insert(ql_first(a_head), (a_elm), a_field); \ 45 | } \ 46 | ql_first(a_head) = (a_elm); \ 47 | } while (0) 48 | 49 | #define ql_tail_insert(a_head, a_elm, a_field) do { \ 50 | if (ql_first(a_head) != NULL) { \ 51 | qr_before_insert(ql_first(a_head), (a_elm), a_field); \ 52 | } \ 53 | ql_first(a_head) = qr_next((a_elm), a_field); \ 54 | } while (0) 55 | 56 | #define ql_remove(a_head, a_elm, a_field) do { \ 57 | if (ql_first(a_head) == (a_elm)) { \ 58 | ql_first(a_head) = qr_next(ql_first(a_head), a_field); \ 59 | } \ 60 | if (ql_first(a_head) != (a_elm)) { \ 61 | qr_remove((a_elm), a_field); \ 62 | } else { \ 63 | ql_first(a_head) = NULL; \ 64 | } \ 65 | } while (0) 66 | 67 | #define ql_head_remove(a_head, a_type, a_field) do { \ 68 | a_type *t = ql_first(a_head); \ 69 | ql_remove((a_head), t, a_field); \ 70 | } while (0) 71 | 72 | #define ql_tail_remove(a_head, a_type, a_field) do { \ 73 | a_type *t = ql_last(a_head, a_field); \ 74 | ql_remove((a_head), t, a_field); \ 75 | } while (0) 76 | 77 | #define ql_foreach(a_var, a_head, a_field) \ 78 | qr_foreach((a_var), ql_first(a_head), a_field) 79 | 80 | #define ql_reverse_foreach(a_var, a_head, a_field) \ 81 | qr_reverse_foreach((a_var), ql_first(a_head), a_field) 82 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/include/jemalloc/internal/qr.h: -------------------------------------------------------------------------------- 1 | /* Ring definitions. */ 2 | #define qr(a_type) \ 3 | struct { \ 4 | a_type *qre_next; \ 5 | a_type *qre_prev; \ 6 | } 7 | 8 | /* Ring functions. */ 9 | #define qr_new(a_qr, a_field) do { \ 10 | (a_qr)->a_field.qre_next = (a_qr); \ 11 | (a_qr)->a_field.qre_prev = (a_qr); \ 12 | } while (0) 13 | 14 | #define qr_next(a_qr, a_field) ((a_qr)->a_field.qre_next) 15 | 16 | #define qr_prev(a_qr, a_field) ((a_qr)->a_field.qre_prev) 17 | 18 | #define qr_before_insert(a_qrelm, a_qr, a_field) do { \ 19 | (a_qr)->a_field.qre_prev = (a_qrelm)->a_field.qre_prev; \ 20 | (a_qr)->a_field.qre_next = (a_qrelm); \ 21 | (a_qr)->a_field.qre_prev->a_field.qre_next = (a_qr); \ 22 | (a_qrelm)->a_field.qre_prev = (a_qr); \ 23 | } while (0) 24 | 25 | #define qr_after_insert(a_qrelm, a_qr, a_field) \ 26 | do \ 27 | { \ 28 | (a_qr)->a_field.qre_next = (a_qrelm)->a_field.qre_next; \ 29 | (a_qr)->a_field.qre_prev = (a_qrelm); \ 30 | (a_qr)->a_field.qre_next->a_field.qre_prev = (a_qr); \ 31 | (a_qrelm)->a_field.qre_next = (a_qr); \ 32 | } while (0) 33 | 34 | #define qr_meld(a_qr_a, a_qr_b, a_field) do { \ 35 | void *t; \ 36 | (a_qr_a)->a_field.qre_prev->a_field.qre_next = (a_qr_b); \ 37 | (a_qr_b)->a_field.qre_prev->a_field.qre_next = (a_qr_a); \ 38 | t = (a_qr_a)->a_field.qre_prev; \ 39 | (a_qr_a)->a_field.qre_prev = (a_qr_b)->a_field.qre_prev; \ 40 | (a_qr_b)->a_field.qre_prev = t; \ 41 | } while (0) 42 | 43 | /* 44 | * qr_meld() and qr_split() are functionally equivalent, so there's no need to 45 | * have two copies of the code. 46 | */ 47 | #define qr_split(a_qr_a, a_qr_b, a_field) \ 48 | qr_meld((a_qr_a), (a_qr_b), a_field) 49 | 50 | #define qr_remove(a_qr, a_field) do { \ 51 | (a_qr)->a_field.qre_prev->a_field.qre_next \ 52 | = (a_qr)->a_field.qre_next; \ 53 | (a_qr)->a_field.qre_next->a_field.qre_prev \ 54 | = (a_qr)->a_field.qre_prev; \ 55 | (a_qr)->a_field.qre_next = (a_qr); \ 56 | (a_qr)->a_field.qre_prev = (a_qr); \ 57 | } while (0) 58 | 59 | #define qr_foreach(var, a_qr, a_field) \ 60 | for ((var) = (a_qr); \ 61 | (var) != NULL; \ 62 | (var) = (((var)->a_field.qre_next != (a_qr)) \ 63 | ? (var)->a_field.qre_next : NULL)) 64 | 65 | #define qr_reverse_foreach(var, a_qr, a_field) \ 66 | for ((var) = ((a_qr) != NULL) ? qr_prev(a_qr, a_field) : NULL; \ 67 | (var) != NULL; \ 68 | (var) = (((var) != (a_qr)) \ 69 | ? (var)->a_field.qre_prev : NULL)) 70 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/include/jemalloc/internal/quarantine.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | #ifdef JEMALLOC_H_TYPES 3 | 4 | typedef struct quarantine_obj_s quarantine_obj_t; 5 | typedef struct quarantine_s quarantine_t; 6 | 7 | /* Default per thread quarantine size if valgrind is enabled. */ 8 | #define JEMALLOC_VALGRIND_QUARANTINE_DEFAULT (ZU(1) << 24) 9 | 10 | #endif /* JEMALLOC_H_TYPES */ 11 | /******************************************************************************/ 12 | #ifdef JEMALLOC_H_STRUCTS 13 | 14 | struct quarantine_obj_s { 15 | void *ptr; 16 | size_t usize; 17 | }; 18 | 19 | struct quarantine_s { 20 | size_t curbytes; 21 | size_t curobjs; 22 | size_t first; 23 | #define LG_MAXOBJS_INIT 10 24 | size_t lg_maxobjs; 25 | quarantine_obj_t objs[1]; /* Dynamically sized ring buffer. */ 26 | }; 27 | 28 | #endif /* JEMALLOC_H_STRUCTS */ 29 | /******************************************************************************/ 30 | #ifdef JEMALLOC_H_EXTERNS 31 | 32 | void quarantine_alloc_hook_work(tsd_t *tsd); 33 | void quarantine(tsd_t *tsd, void *ptr); 34 | void quarantine_cleanup(tsd_t *tsd); 35 | 36 | #endif /* JEMALLOC_H_EXTERNS */ 37 | /******************************************************************************/ 38 | #ifdef JEMALLOC_H_INLINES 39 | 40 | #ifndef JEMALLOC_ENABLE_INLINE 41 | void quarantine_alloc_hook(void); 42 | #endif 43 | 44 | #if (defined(JEMALLOC_ENABLE_INLINE) || defined(JEMALLOC_QUARANTINE_C_)) 45 | JEMALLOC_ALWAYS_INLINE void 46 | quarantine_alloc_hook(void) 47 | { 48 | tsd_t *tsd; 49 | 50 | assert(config_fill && opt_quarantine); 51 | 52 | tsd = tsd_fetch(); 53 | if (tsd_quarantine_get(tsd) == NULL) 54 | quarantine_alloc_hook_work(tsd); 55 | } 56 | #endif 57 | 58 | #endif /* JEMALLOC_H_INLINES */ 59 | /******************************************************************************/ 60 | 61 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/include/jemalloc/internal/spin.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | #ifdef JEMALLOC_H_TYPES 3 | 4 | typedef struct spin_s spin_t; 5 | 6 | #endif /* JEMALLOC_H_TYPES */ 7 | /******************************************************************************/ 8 | #ifdef JEMALLOC_H_STRUCTS 9 | 10 | struct spin_s { 11 | unsigned iteration; 12 | }; 13 | 14 | #endif /* JEMALLOC_H_STRUCTS */ 15 | /******************************************************************************/ 16 | #ifdef JEMALLOC_H_EXTERNS 17 | 18 | #endif /* JEMALLOC_H_EXTERNS */ 19 | /******************************************************************************/ 20 | #ifdef JEMALLOC_H_INLINES 21 | 22 | #ifndef JEMALLOC_ENABLE_INLINE 23 | void spin_init(spin_t *spin); 24 | void spin_adaptive(spin_t *spin); 25 | #endif 26 | 27 | #if (defined(JEMALLOC_ENABLE_INLINE) || defined(JEMALLOC_SPIN_C_)) 28 | JEMALLOC_INLINE void 29 | spin_init(spin_t *spin) 30 | { 31 | 32 | spin->iteration = 0; 33 | } 34 | 35 | JEMALLOC_INLINE void 36 | spin_adaptive(spin_t *spin) 37 | { 38 | volatile uint64_t i; 39 | 40 | for (i = 0; i < (KQU(1) << spin->iteration); i++) 41 | CPU_SPINWAIT; 42 | 43 | if (spin->iteration < 63) 44 | spin->iteration++; 45 | } 46 | 47 | #endif 48 | 49 | #endif /* JEMALLOC_H_INLINES */ 50 | /******************************************************************************/ 51 | 52 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/include/jemalloc/internal/ticker.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | #ifdef JEMALLOC_H_TYPES 3 | 4 | typedef struct ticker_s ticker_t; 5 | 6 | #endif /* JEMALLOC_H_TYPES */ 7 | /******************************************************************************/ 8 | #ifdef JEMALLOC_H_STRUCTS 9 | 10 | struct ticker_s { 11 | int32_t tick; 12 | int32_t nticks; 13 | }; 14 | 15 | #endif /* JEMALLOC_H_STRUCTS */ 16 | /******************************************************************************/ 17 | #ifdef JEMALLOC_H_EXTERNS 18 | 19 | #endif /* JEMALLOC_H_EXTERNS */ 20 | /******************************************************************************/ 21 | #ifdef JEMALLOC_H_INLINES 22 | 23 | #ifndef JEMALLOC_ENABLE_INLINE 24 | void ticker_init(ticker_t *ticker, int32_t nticks); 25 | void ticker_copy(ticker_t *ticker, const ticker_t *other); 26 | int32_t ticker_read(const ticker_t *ticker); 27 | bool ticker_ticks(ticker_t *ticker, int32_t nticks); 28 | bool ticker_tick(ticker_t *ticker); 29 | #endif 30 | 31 | #if (defined(JEMALLOC_ENABLE_INLINE) || defined(JEMALLOC_TICKER_C_)) 32 | JEMALLOC_INLINE void 33 | ticker_init(ticker_t *ticker, int32_t nticks) 34 | { 35 | 36 | ticker->tick = nticks; 37 | ticker->nticks = nticks; 38 | } 39 | 40 | JEMALLOC_INLINE void 41 | ticker_copy(ticker_t *ticker, const ticker_t *other) 42 | { 43 | 44 | *ticker = *other; 45 | } 46 | 47 | JEMALLOC_INLINE int32_t 48 | ticker_read(const ticker_t *ticker) 49 | { 50 | 51 | return (ticker->tick); 52 | } 53 | 54 | JEMALLOC_INLINE bool 55 | ticker_ticks(ticker_t *ticker, int32_t nticks) 56 | { 57 | 58 | if (unlikely(ticker->tick < nticks)) { 59 | ticker->tick = ticker->nticks; 60 | return (true); 61 | } 62 | ticker->tick -= nticks; 63 | return(false); 64 | } 65 | 66 | JEMALLOC_INLINE bool 67 | ticker_tick(ticker_t *ticker) 68 | { 69 | 70 | return (ticker_ticks(ticker, 1)); 71 | } 72 | #endif 73 | 74 | #endif /* JEMALLOC_H_INLINES */ 75 | /******************************************************************************/ 76 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/include/jemalloc/jemalloc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | objroot=$1 4 | 5 | cat < 5 | 6 | /* MSVC doesn't define _Bool or bool in C, but does have BOOL */ 7 | /* Note this doesn't pass autoconf's test because (bool) 0.5 != true */ 8 | /* Clang-cl uses MSVC headers, so needs msvc_compat, but has _Bool as 9 | * a built-in type. */ 10 | #ifndef __clang__ 11 | typedef BOOL _Bool; 12 | #endif 13 | 14 | #define bool _Bool 15 | #define true 1 16 | #define false 0 17 | 18 | #define __bool_true_false_are_defined 1 19 | 20 | #endif /* stdbool_h */ 21 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/include/msvc_compat/strings.h: -------------------------------------------------------------------------------- 1 | #ifndef strings_h 2 | #define strings_h 3 | 4 | /* MSVC doesn't define ffs/ffsl. This dummy strings.h header is provided 5 | * for both */ 6 | #ifdef _MSC_VER 7 | # include 8 | # pragma intrinsic(_BitScanForward) 9 | static __forceinline int ffsl(long x) 10 | { 11 | unsigned long i; 12 | 13 | if (_BitScanForward(&i, x)) 14 | return (i + 1); 15 | return (0); 16 | } 17 | 18 | static __forceinline int ffs(int x) 19 | { 20 | 21 | return (ffsl(x)); 22 | } 23 | 24 | # ifdef _M_X64 25 | # pragma intrinsic(_BitScanForward64) 26 | # endif 27 | 28 | static __forceinline int ffsll(unsigned __int64 x) 29 | { 30 | unsigned long i; 31 | #ifdef _M_X64 32 | if (_BitScanForward64(&i, x)) 33 | return (i + 1); 34 | return (0); 35 | #else 36 | // Fallback for 32-bit build where 64-bit version not available 37 | // assuming little endian 38 | union { 39 | unsigned __int64 ll; 40 | unsigned long l[2]; 41 | } s; 42 | 43 | s.ll = x; 44 | 45 | if (_BitScanForward(&i, s.l[0])) 46 | return (i + 1); 47 | else if(_BitScanForward(&i, s.l[1])) 48 | return (i + 33); 49 | return (0); 50 | #endif 51 | } 52 | 53 | #else 54 | # define ffsll(x) __builtin_ffsll(x) 55 | # define ffsl(x) __builtin_ffsl(x) 56 | # define ffs(x) __builtin_ffs(x) 57 | #endif 58 | 59 | #endif /* strings_h */ 60 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/include/msvc_compat/windows_extra.h: -------------------------------------------------------------------------------- 1 | #ifndef MSVC_COMPAT_WINDOWS_EXTRA_H 2 | #define MSVC_COMPAT_WINDOWS_EXTRA_H 3 | 4 | #include 5 | 6 | #endif /* MSVC_COMPAT_WINDOWS_EXTRA_H */ 7 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/jemalloc.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | install_suffix=@install_suffix@ 6 | 7 | Name: jemalloc 8 | Description: A general purpose malloc(3) implementation that emphasizes fragmentation avoidance and scalable concurrency support. 9 | URL: http://jemalloc.net/ 10 | Version: @jemalloc_version@ 11 | Cflags: -I${includedir} 12 | Libs: -L${libdir} -ljemalloc${install_suffix} 13 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/msvc/ReadMe.txt: -------------------------------------------------------------------------------- 1 | 2 | How to build jemalloc for Windows 3 | ================================= 4 | 5 | 1. Install Cygwin with at least the following packages: 6 | * autoconf 7 | * autogen 8 | * gawk 9 | * grep 10 | * sed 11 | 12 | 2. Install Visual Studio 2015 with Visual C++ 13 | 14 | 3. Add Cygwin\bin to the PATH environment variable 15 | 16 | 4. Open "VS2015 x86 Native Tools Command Prompt" 17 | (note: x86/x64 doesn't matter at this point) 18 | 19 | 5. Generate header files: 20 | sh -c "CC=cl ./autogen.sh" 21 | 22 | 6. Now the project can be opened and built in Visual Studio: 23 | msvc\jemalloc_vc2015.sln 24 | 25 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/msvc/projects/vc2015/test_threads/test_threads.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | int test_threads(); 4 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/msvc/projects/vc2015/test_threads/test_threads.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | 14 | 15 | Source Files 16 | 17 | 18 | Source Files 19 | 20 | 21 | 22 | 23 | Header Files 24 | 25 | 26 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/msvc/projects/vc2015/test_threads/test_threads_main.cpp: -------------------------------------------------------------------------------- 1 | #include "test_threads.h" 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std::chrono_literals; 7 | 8 | int main(int argc, char** argv) 9 | { 10 | int rc = test_threads(); 11 | return rc; 12 | } 13 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/scripts/gen_travis.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from itertools import combinations 4 | 5 | travis_template = """\ 6 | language: generic 7 | 8 | matrix: 9 | include: 10 | %s 11 | 12 | before_script: 13 | - autoconf 14 | - ./configure ${COMPILER_FLAGS:+ \ 15 | CC="$CC $COMPILER_FLAGS" } \ 16 | $CONFIGURE_FLAGS 17 | - make -j3 18 | - make -j3 tests 19 | 20 | script: 21 | - make check 22 | """ 23 | 24 | # The 'default' configuration is gcc, on linux, with no compiler or configure 25 | # flags. We also test with clang, -m32, --enable-debug, --enable-prof, 26 | # --disable-stats, and --disable-tcache. To avoid abusing travis though, we 27 | # don't test all 2**7 = 128 possible combinations of these; instead, we only 28 | # test combinations of up to 2 'unusual' settings, under the hope that bugs 29 | # involving interactions of such settings are rare. 30 | # things at once, for C(7, 0) + C(7, 1) + C(7, 2) = 29 31 | MAX_UNUSUAL_OPTIONS = 2 32 | 33 | os_default = 'linux' 34 | os_unusual = 'osx' 35 | 36 | compilers_default = 'CC=gcc' 37 | compilers_unusual = 'CC=clang' 38 | 39 | compiler_flag_unusuals = ['-m32'] 40 | 41 | configure_flag_unusuals = [ 42 | '--enable-debug', '--enable-prof', '--disable-stats', '--disable-tcache', 43 | ] 44 | 45 | all_unusuals = ( 46 | [os_unusual] + [compilers_unusual] + compiler_flag_unusuals 47 | + configure_flag_unusuals 48 | ) 49 | 50 | unusual_combinations_to_test = [] 51 | for i in xrange(MAX_UNUSUAL_OPTIONS + 1): 52 | unusual_combinations_to_test += combinations(all_unusuals, i) 53 | 54 | include_rows = "" 55 | for unusual_combination in unusual_combinations_to_test: 56 | os = os_default 57 | if os_unusual in unusual_combination: 58 | os = os_unusual 59 | 60 | compilers = compilers_default 61 | if compilers_unusual in unusual_combination: 62 | compilers = compilers_unusual 63 | 64 | compiler_flags = [ 65 | x for x in unusual_combination if x in compiler_flag_unusuals] 66 | 67 | configure_flags = [ 68 | x for x in unusual_combination if x in configure_flag_unusuals] 69 | 70 | # Filter out an unsupported configuration - heap profiling on OS X. 71 | if os == 'osx' and '--enable-prof' in configure_flags: 72 | continue 73 | 74 | env_string = '{} COMPILER_FLAGS="{}" CONFIGURE_FLAGS="{}"'.format( 75 | compilers, " ".join(compiler_flags), " ".join(configure_flags)) 76 | 77 | include_rows += ' - os: %s\n' % os 78 | include_rows += ' env: %s\n' % env_string 79 | if '-m32' in unusual_combination and os == 'linux': 80 | include_rows += ' addons:\n' 81 | include_rows += ' apt:\n' 82 | include_rows += ' packages:\n' 83 | include_rows += ' - gcc-multilib\n' 84 | 85 | print travis_template % include_rows 86 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/src/atomic.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_ATOMIC_C_ 2 | #include "jemalloc/internal/jemalloc_internal.h" 3 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/src/chunk_mmap.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_CHUNK_MMAP_C_ 2 | #include "jemalloc/internal/jemalloc_internal.h" 3 | 4 | /******************************************************************************/ 5 | 6 | static void * 7 | chunk_alloc_mmap_slow(size_t size, size_t alignment, bool *zero, bool *commit) 8 | { 9 | void *ret; 10 | size_t alloc_size; 11 | 12 | alloc_size = size + alignment - PAGE; 13 | /* Beware size_t wrap-around. */ 14 | if (alloc_size < size) 15 | return (NULL); 16 | do { 17 | void *pages; 18 | size_t leadsize; 19 | pages = pages_map(NULL, alloc_size, commit); 20 | if (pages == NULL) 21 | return (NULL); 22 | leadsize = ALIGNMENT_CEILING((uintptr_t)pages, alignment) - 23 | (uintptr_t)pages; 24 | ret = pages_trim(pages, alloc_size, leadsize, size, commit); 25 | } while (ret == NULL); 26 | 27 | assert(ret != NULL); 28 | *zero = true; 29 | return (ret); 30 | } 31 | 32 | void * 33 | chunk_alloc_mmap(void *new_addr, size_t size, size_t alignment, bool *zero, 34 | bool *commit) 35 | { 36 | void *ret; 37 | size_t offset; 38 | 39 | /* 40 | * Ideally, there would be a way to specify alignment to mmap() (like 41 | * NetBSD has), but in the absence of such a feature, we have to work 42 | * hard to efficiently create aligned mappings. The reliable, but 43 | * slow method is to create a mapping that is over-sized, then trim the 44 | * excess. However, that always results in one or two calls to 45 | * pages_unmap(). 46 | * 47 | * Optimistically try mapping precisely the right amount before falling 48 | * back to the slow method, with the expectation that the optimistic 49 | * approach works most of the time. 50 | */ 51 | 52 | assert(alignment != 0); 53 | assert((alignment & chunksize_mask) == 0); 54 | 55 | ret = pages_map(new_addr, size, commit); 56 | if (ret == NULL || ret == new_addr) 57 | return (ret); 58 | assert(new_addr == NULL); 59 | offset = ALIGNMENT_ADDR2OFFSET(ret, alignment); 60 | if (offset != 0) { 61 | pages_unmap(ret, size); 62 | return (chunk_alloc_mmap_slow(size, alignment, zero, commit)); 63 | } 64 | 65 | assert(ret != NULL); 66 | *zero = true; 67 | return (ret); 68 | } 69 | 70 | bool 71 | chunk_dalloc_mmap(void *chunk, size_t size) 72 | { 73 | 74 | if (config_munmap) 75 | pages_unmap(chunk, size); 76 | 77 | return (!config_munmap); 78 | } 79 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/src/extent.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_EXTENT_C_ 2 | #include "jemalloc/internal/jemalloc_internal.h" 3 | 4 | /******************************************************************************/ 5 | 6 | #ifndef JEMALLOC_JET 7 | static 8 | #endif 9 | size_t 10 | extent_size_quantize_floor(size_t size) { 11 | size_t ret; 12 | szind_t ind; 13 | 14 | assert(size > 0); 15 | 16 | ind = size2index(size + 1); 17 | if (ind == 0) { 18 | /* Avoid underflow. */ 19 | return (index2size(0)); 20 | } 21 | ret = index2size(ind - 1); 22 | assert(ret <= size); 23 | return (ret); 24 | } 25 | 26 | size_t 27 | extent_size_quantize_ceil(size_t size) { 28 | size_t ret; 29 | 30 | assert(size > 0); 31 | 32 | ret = extent_size_quantize_floor(size); 33 | if (ret < size) { 34 | /* 35 | * Skip a quantization that may have an adequately large extent, 36 | * because under-sized extents may be mixed in. This only 37 | * happens when an unusual size is requested, i.e. for aligned 38 | * allocation, and is just one of several places where linear 39 | * search would potentially find sufficiently aligned available 40 | * memory somewhere lower. 41 | */ 42 | ret = index2size(size2index(ret + 1)); 43 | } 44 | return ret; 45 | } 46 | 47 | JEMALLOC_INLINE_C int 48 | extent_sz_comp(const extent_node_t *a, const extent_node_t *b) 49 | { 50 | size_t a_qsize = extent_size_quantize_floor(extent_node_size_get(a)); 51 | size_t b_qsize = extent_size_quantize_floor(extent_node_size_get(b)); 52 | 53 | return ((a_qsize > b_qsize) - (a_qsize < b_qsize)); 54 | } 55 | 56 | JEMALLOC_INLINE_C int 57 | extent_sn_comp(const extent_node_t *a, const extent_node_t *b) 58 | { 59 | size_t a_sn = extent_node_sn_get(a); 60 | size_t b_sn = extent_node_sn_get(b); 61 | 62 | return ((a_sn > b_sn) - (a_sn < b_sn)); 63 | } 64 | 65 | JEMALLOC_INLINE_C int 66 | extent_ad_comp(const extent_node_t *a, const extent_node_t *b) 67 | { 68 | uintptr_t a_addr = (uintptr_t)extent_node_addr_get(a); 69 | uintptr_t b_addr = (uintptr_t)extent_node_addr_get(b); 70 | 71 | return ((a_addr > b_addr) - (a_addr < b_addr)); 72 | } 73 | 74 | JEMALLOC_INLINE_C int 75 | extent_szsnad_comp(const extent_node_t *a, const extent_node_t *b) 76 | { 77 | int ret; 78 | 79 | ret = extent_sz_comp(a, b); 80 | if (ret != 0) 81 | return (ret); 82 | 83 | ret = extent_sn_comp(a, b); 84 | if (ret != 0) 85 | return (ret); 86 | 87 | ret = extent_ad_comp(a, b); 88 | return (ret); 89 | } 90 | 91 | /* Generate red-black tree functions. */ 92 | rb_gen(, extent_tree_szsnad_, extent_tree_t, extent_node_t, szsnad_link, 93 | extent_szsnad_comp) 94 | 95 | /* Generate red-black tree functions. */ 96 | rb_gen(, extent_tree_ad_, extent_tree_t, extent_node_t, ad_link, extent_ad_comp) 97 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/src/hash.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_HASH_C_ 2 | #include "jemalloc/internal/jemalloc_internal.h" 3 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/src/mb.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_MB_C_ 2 | #include "jemalloc/internal/jemalloc_internal.h" 3 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/src/prng.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_PRNG_C_ 2 | #include "jemalloc/internal/jemalloc_internal.h" 3 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/src/spin.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_SPIN_C_ 2 | #include "jemalloc/internal/jemalloc_internal.h" 3 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/src/ticker.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_TICKER_C_ 2 | #include "jemalloc/internal/jemalloc_internal.h" 3 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/src/valgrind.c: -------------------------------------------------------------------------------- 1 | #include "jemalloc/internal/jemalloc_internal.h" 2 | #ifndef JEMALLOC_VALGRIND 3 | # error "This source file is for Valgrind integration." 4 | #endif 5 | 6 | #include 7 | 8 | void 9 | valgrind_make_mem_noaccess(void *ptr, size_t usize) 10 | { 11 | 12 | VALGRIND_MAKE_MEM_NOACCESS(ptr, usize); 13 | } 14 | 15 | void 16 | valgrind_make_mem_undefined(void *ptr, size_t usize) 17 | { 18 | 19 | VALGRIND_MAKE_MEM_UNDEFINED(ptr, usize); 20 | } 21 | 22 | void 23 | valgrind_make_mem_defined(void *ptr, size_t usize) 24 | { 25 | 26 | VALGRIND_MAKE_MEM_DEFINED(ptr, usize); 27 | } 28 | 29 | void 30 | valgrind_freelike_block(void *ptr, size_t usize) 31 | { 32 | 33 | VALGRIND_FREELIKE_BLOCK(ptr, usize); 34 | } 35 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/include/test/btalloc.h: -------------------------------------------------------------------------------- 1 | /* btalloc() provides a mechanism for allocating via permuted backtraces. */ 2 | void *btalloc(size_t size, unsigned bits); 3 | 4 | #define btalloc_n_proto(n) \ 5 | void *btalloc_##n(size_t size, unsigned bits); 6 | btalloc_n_proto(0) 7 | btalloc_n_proto(1) 8 | 9 | #define btalloc_n_gen(n) \ 10 | void * \ 11 | btalloc_##n(size_t size, unsigned bits) \ 12 | { \ 13 | void *p; \ 14 | \ 15 | if (bits == 0) \ 16 | p = mallocx(size, 0); \ 17 | else { \ 18 | switch (bits & 0x1U) { \ 19 | case 0: \ 20 | p = (btalloc_0(size, bits >> 1)); \ 21 | break; \ 22 | case 1: \ 23 | p = (btalloc_1(size, bits >> 1)); \ 24 | break; \ 25 | default: not_reached(); \ 26 | } \ 27 | } \ 28 | /* Intentionally sabotage tail call optimization. */ \ 29 | assert_ptr_not_null(p, "Unexpected mallocx() failure"); \ 30 | return (p); \ 31 | } 32 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/include/test/jemalloc_test_defs.h.in: -------------------------------------------------------------------------------- 1 | #include "jemalloc/internal/jemalloc_internal_defs.h" 2 | #include "jemalloc/internal/jemalloc_internal_decls.h" 3 | 4 | /* 5 | * For use by SFMT. configure.ac doesn't actually define HAVE_SSE2 because its 6 | * dependencies are notoriously unportable in practice. 7 | */ 8 | #undef HAVE_SSE2 9 | #undef HAVE_ALTIVEC 10 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/include/test/mtx.h: -------------------------------------------------------------------------------- 1 | /* 2 | * mtx is a slightly simplified version of malloc_mutex. This code duplication 3 | * is unfortunate, but there are allocator bootstrapping considerations that 4 | * would leak into the test infrastructure if malloc_mutex were used directly 5 | * in tests. 6 | */ 7 | 8 | typedef struct { 9 | #ifdef _WIN32 10 | CRITICAL_SECTION lock; 11 | #elif (defined(JEMALLOC_OS_UNFAIR_LOCK)) 12 | os_unfair_lock lock; 13 | #elif (defined(JEMALLOC_OSSPIN)) 14 | OSSpinLock lock; 15 | #else 16 | pthread_mutex_t lock; 17 | #endif 18 | } mtx_t; 19 | 20 | bool mtx_init(mtx_t *mtx); 21 | void mtx_fini(mtx_t *mtx); 22 | void mtx_lock(mtx_t *mtx); 23 | void mtx_unlock(mtx_t *mtx); 24 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/include/test/thd.h: -------------------------------------------------------------------------------- 1 | /* Abstraction layer for threading in tests. */ 2 | #ifdef _WIN32 3 | typedef HANDLE thd_t; 4 | #else 5 | typedef pthread_t thd_t; 6 | #endif 7 | 8 | void thd_create(thd_t *thd, void *(*proc)(void *), void *arg); 9 | void thd_join(thd_t thd, void **ret); 10 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/include/test/timer.h: -------------------------------------------------------------------------------- 1 | /* Simple timer, for use in benchmark reporting. */ 2 | 3 | typedef struct { 4 | nstime_t t0; 5 | nstime_t t1; 6 | } timedelta_t; 7 | 8 | void timer_start(timedelta_t *timer); 9 | void timer_stop(timedelta_t *timer); 10 | uint64_t timer_usec(const timedelta_t *timer); 11 | void timer_ratio(timedelta_t *a, timedelta_t *b, char *buf, size_t buflen); 12 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/integration/MALLOCX_ARENA.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | #define NTHREADS 10 4 | 5 | static bool have_dss = 6 | #ifdef JEMALLOC_DSS 7 | true 8 | #else 9 | false 10 | #endif 11 | ; 12 | 13 | void * 14 | thd_start(void *arg) 15 | { 16 | unsigned thread_ind = (unsigned)(uintptr_t)arg; 17 | unsigned arena_ind; 18 | void *p; 19 | size_t sz; 20 | 21 | sz = sizeof(arena_ind); 22 | assert_d_eq(mallctl("arenas.extend", (void *)&arena_ind, &sz, NULL, 0), 23 | 0, "Error in arenas.extend"); 24 | 25 | if (thread_ind % 4 != 3) { 26 | size_t mib[3]; 27 | size_t miblen = sizeof(mib) / sizeof(size_t); 28 | const char *dss_precs[] = {"disabled", "primary", "secondary"}; 29 | unsigned prec_ind = thread_ind % 30 | (sizeof(dss_precs)/sizeof(char*)); 31 | const char *dss = dss_precs[prec_ind]; 32 | int expected_err = (have_dss || prec_ind == 0) ? 0 : EFAULT; 33 | assert_d_eq(mallctlnametomib("arena.0.dss", mib, &miblen), 0, 34 | "Error in mallctlnametomib()"); 35 | mib[1] = arena_ind; 36 | assert_d_eq(mallctlbymib(mib, miblen, NULL, NULL, (void *)&dss, 37 | sizeof(const char *)), expected_err, 38 | "Error in mallctlbymib()"); 39 | } 40 | 41 | p = mallocx(1, MALLOCX_ARENA(arena_ind)); 42 | assert_ptr_not_null(p, "Unexpected mallocx() error"); 43 | dallocx(p, 0); 44 | 45 | return (NULL); 46 | } 47 | 48 | TEST_BEGIN(test_MALLOCX_ARENA) 49 | { 50 | thd_t thds[NTHREADS]; 51 | unsigned i; 52 | 53 | for (i = 0; i < NTHREADS; i++) { 54 | thd_create(&thds[i], thd_start, 55 | (void *)(uintptr_t)i); 56 | } 57 | 58 | for (i = 0; i < NTHREADS; i++) 59 | thd_join(thds[i], NULL); 60 | } 61 | TEST_END 62 | 63 | int 64 | main(void) 65 | { 66 | 67 | return (test( 68 | test_MALLOCX_ARENA)); 69 | } 70 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/integration/chunk.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "x${enable_fill}" = "x1" ] ; then 4 | export MALLOC_CONF="junk:false" 5 | fi 6 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/integration/mallocx.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "x${enable_fill}" = "x1" ] ; then 4 | export MALLOC_CONF="junk:false" 5 | fi 6 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/integration/overflow.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | TEST_BEGIN(test_overflow) 4 | { 5 | unsigned nhchunks; 6 | size_t mib[4]; 7 | size_t sz, miblen, max_size_class; 8 | void *p; 9 | 10 | sz = sizeof(unsigned); 11 | assert_d_eq(mallctl("arenas.nhchunks", (void *)&nhchunks, &sz, NULL, 0), 12 | 0, "Unexpected mallctl() error"); 13 | 14 | miblen = sizeof(mib) / sizeof(size_t); 15 | assert_d_eq(mallctlnametomib("arenas.hchunk.0.size", mib, &miblen), 0, 16 | "Unexpected mallctlnametomib() error"); 17 | mib[2] = nhchunks - 1; 18 | 19 | sz = sizeof(size_t); 20 | assert_d_eq(mallctlbymib(mib, miblen, (void *)&max_size_class, &sz, 21 | NULL, 0), 0, "Unexpected mallctlbymib() error"); 22 | 23 | assert_ptr_null(malloc(max_size_class + 1), 24 | "Expected OOM due to over-sized allocation request"); 25 | assert_ptr_null(malloc(SIZE_T_MAX), 26 | "Expected OOM due to over-sized allocation request"); 27 | 28 | assert_ptr_null(calloc(1, max_size_class + 1), 29 | "Expected OOM due to over-sized allocation request"); 30 | assert_ptr_null(calloc(1, SIZE_T_MAX), 31 | "Expected OOM due to over-sized allocation request"); 32 | 33 | p = malloc(1); 34 | assert_ptr_not_null(p, "Unexpected malloc() OOM"); 35 | assert_ptr_null(realloc(p, max_size_class + 1), 36 | "Expected OOM due to over-sized allocation request"); 37 | assert_ptr_null(realloc(p, SIZE_T_MAX), 38 | "Expected OOM due to over-sized allocation request"); 39 | free(p); 40 | } 41 | TEST_END 42 | 43 | int 44 | main(void) 45 | { 46 | 47 | return (test( 48 | test_overflow)); 49 | } 50 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/integration/sdallocx.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | #define MAXALIGN (((size_t)1) << 22) 4 | #define NITER 3 5 | 6 | TEST_BEGIN(test_basic) 7 | { 8 | void *ptr = mallocx(64, 0); 9 | sdallocx(ptr, 64, 0); 10 | } 11 | TEST_END 12 | 13 | TEST_BEGIN(test_alignment_and_size) 14 | { 15 | size_t nsz, sz, alignment, total; 16 | unsigned i; 17 | void *ps[NITER]; 18 | 19 | for (i = 0; i < NITER; i++) 20 | ps[i] = NULL; 21 | 22 | for (alignment = 8; 23 | alignment <= MAXALIGN; 24 | alignment <<= 1) { 25 | total = 0; 26 | for (sz = 1; 27 | sz < 3 * alignment && sz < (1U << 31); 28 | sz += (alignment >> (LG_SIZEOF_PTR-1)) - 1) { 29 | for (i = 0; i < NITER; i++) { 30 | nsz = nallocx(sz, MALLOCX_ALIGN(alignment) | 31 | MALLOCX_ZERO); 32 | ps[i] = mallocx(sz, MALLOCX_ALIGN(alignment) | 33 | MALLOCX_ZERO); 34 | total += nsz; 35 | if (total >= (MAXALIGN << 1)) 36 | break; 37 | } 38 | for (i = 0; i < NITER; i++) { 39 | if (ps[i] != NULL) { 40 | sdallocx(ps[i], sz, 41 | MALLOCX_ALIGN(alignment)); 42 | ps[i] = NULL; 43 | } 44 | } 45 | } 46 | } 47 | } 48 | TEST_END 49 | 50 | int 51 | main(void) 52 | { 53 | 54 | return (test( 55 | test_basic, 56 | test_alignment_and_size)); 57 | } 58 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/integration/thread_arena.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | #define NTHREADS 10 4 | 5 | void * 6 | thd_start(void *arg) 7 | { 8 | unsigned main_arena_ind = *(unsigned *)arg; 9 | void *p; 10 | unsigned arena_ind; 11 | size_t size; 12 | int err; 13 | 14 | p = malloc(1); 15 | assert_ptr_not_null(p, "Error in malloc()"); 16 | free(p); 17 | 18 | size = sizeof(arena_ind); 19 | if ((err = mallctl("thread.arena", (void *)&arena_ind, &size, 20 | (void *)&main_arena_ind, sizeof(main_arena_ind)))) { 21 | char buf[BUFERROR_BUF]; 22 | 23 | buferror(err, buf, sizeof(buf)); 24 | test_fail("Error in mallctl(): %s", buf); 25 | } 26 | 27 | size = sizeof(arena_ind); 28 | if ((err = mallctl("thread.arena", (void *)&arena_ind, &size, NULL, 29 | 0))) { 30 | char buf[BUFERROR_BUF]; 31 | 32 | buferror(err, buf, sizeof(buf)); 33 | test_fail("Error in mallctl(): %s", buf); 34 | } 35 | assert_u_eq(arena_ind, main_arena_ind, 36 | "Arena index should be same as for main thread"); 37 | 38 | return (NULL); 39 | } 40 | 41 | TEST_BEGIN(test_thread_arena) 42 | { 43 | void *p; 44 | unsigned arena_ind; 45 | size_t size; 46 | int err; 47 | thd_t thds[NTHREADS]; 48 | unsigned i; 49 | 50 | p = malloc(1); 51 | assert_ptr_not_null(p, "Error in malloc()"); 52 | 53 | size = sizeof(arena_ind); 54 | if ((err = mallctl("thread.arena", (void *)&arena_ind, &size, NULL, 55 | 0))) { 56 | char buf[BUFERROR_BUF]; 57 | 58 | buferror(err, buf, sizeof(buf)); 59 | test_fail("Error in mallctl(): %s", buf); 60 | } 61 | 62 | for (i = 0; i < NTHREADS; i++) { 63 | thd_create(&thds[i], thd_start, 64 | (void *)&arena_ind); 65 | } 66 | 67 | for (i = 0; i < NTHREADS; i++) { 68 | intptr_t join_ret; 69 | thd_join(thds[i], (void *)&join_ret); 70 | assert_zd_eq(join_ret, 0, "Unexpected thread join error"); 71 | } 72 | } 73 | TEST_END 74 | 75 | int 76 | main(void) 77 | { 78 | 79 | return (test( 80 | test_thread_arena)); 81 | } 82 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/integration/thread_tcache_enabled.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | static const bool config_tcache = 4 | #ifdef JEMALLOC_TCACHE 5 | true 6 | #else 7 | false 8 | #endif 9 | ; 10 | 11 | void * 12 | thd_start(void *arg) 13 | { 14 | int err; 15 | size_t sz; 16 | bool e0, e1; 17 | 18 | sz = sizeof(bool); 19 | if ((err = mallctl("thread.tcache.enabled", (void *)&e0, &sz, NULL, 20 | 0))) { 21 | if (err == ENOENT) { 22 | assert_false(config_tcache, 23 | "ENOENT should only be returned if tcache is " 24 | "disabled"); 25 | } 26 | goto label_ENOENT; 27 | } 28 | 29 | if (e0) { 30 | e1 = false; 31 | assert_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz, 32 | (void *)&e1, sz), 0, "Unexpected mallctl() error"); 33 | assert_true(e0, "tcache should be enabled"); 34 | } 35 | 36 | e1 = true; 37 | assert_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz, 38 | (void *)&e1, sz), 0, "Unexpected mallctl() error"); 39 | assert_false(e0, "tcache should be disabled"); 40 | 41 | e1 = true; 42 | assert_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz, 43 | (void *)&e1, sz), 0, "Unexpected mallctl() error"); 44 | assert_true(e0, "tcache should be enabled"); 45 | 46 | e1 = false; 47 | assert_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz, 48 | (void *)&e1, sz), 0, "Unexpected mallctl() error"); 49 | assert_true(e0, "tcache should be enabled"); 50 | 51 | e1 = false; 52 | assert_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz, 53 | (void *)&e1, sz), 0, "Unexpected mallctl() error"); 54 | assert_false(e0, "tcache should be disabled"); 55 | 56 | free(malloc(1)); 57 | e1 = true; 58 | assert_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz, 59 | (void *)&e1, sz), 0, "Unexpected mallctl() error"); 60 | assert_false(e0, "tcache should be disabled"); 61 | 62 | free(malloc(1)); 63 | e1 = true; 64 | assert_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz, 65 | (void *)&e1, sz), 0, "Unexpected mallctl() error"); 66 | assert_true(e0, "tcache should be enabled"); 67 | 68 | free(malloc(1)); 69 | e1 = false; 70 | assert_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz, 71 | (void *)&e1, sz), 0, "Unexpected mallctl() error"); 72 | assert_true(e0, "tcache should be enabled"); 73 | 74 | free(malloc(1)); 75 | e1 = false; 76 | assert_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz, 77 | (void *)&e1, sz), 0, "Unexpected mallctl() error"); 78 | assert_false(e0, "tcache should be disabled"); 79 | 80 | free(malloc(1)); 81 | return (NULL); 82 | label_ENOENT: 83 | test_skip("\"thread.tcache.enabled\" mallctl not available"); 84 | return (NULL); 85 | } 86 | 87 | TEST_BEGIN(test_main_thread) 88 | { 89 | 90 | thd_start(NULL); 91 | } 92 | TEST_END 93 | 94 | TEST_BEGIN(test_subthread) 95 | { 96 | thd_t thd; 97 | 98 | thd_create(&thd, thd_start, NULL); 99 | thd_join(thd, NULL); 100 | } 101 | TEST_END 102 | 103 | int 104 | main(void) 105 | { 106 | 107 | /* Run tests multiple times to check for bad interactions. */ 108 | return (test( 109 | test_main_thread, 110 | test_subthread, 111 | test_main_thread, 112 | test_subthread, 113 | test_main_thread)); 114 | } 115 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/integration/xallocx.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "x${enable_fill}" = "x1" ] ; then 4 | export MALLOC_CONF="junk:false" 5 | fi 6 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/src/btalloc.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | void * 4 | btalloc(size_t size, unsigned bits) 5 | { 6 | 7 | return (btalloc_0(size, bits)); 8 | } 9 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/src/btalloc_0.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | btalloc_n_gen(0) 4 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/src/btalloc_1.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | btalloc_n_gen(1) 4 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/src/math.c: -------------------------------------------------------------------------------- 1 | #define MATH_C_ 2 | #include "test/jemalloc_test.h" 3 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/src/mq.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | /* 4 | * Sleep for approximately ns nanoseconds. No lower *nor* upper bound on sleep 5 | * time is guaranteed. 6 | */ 7 | void 8 | mq_nanosleep(unsigned ns) 9 | { 10 | 11 | assert(ns <= 1000*1000*1000); 12 | 13 | #ifdef _WIN32 14 | Sleep(ns / 1000); 15 | #else 16 | { 17 | struct timespec timeout; 18 | 19 | if (ns < 1000*1000*1000) { 20 | timeout.tv_sec = 0; 21 | timeout.tv_nsec = ns; 22 | } else { 23 | timeout.tv_sec = 1; 24 | timeout.tv_nsec = 0; 25 | } 26 | nanosleep(&timeout, NULL); 27 | } 28 | #endif 29 | } 30 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/src/mtx.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | #ifndef _CRT_SPINCOUNT 4 | #define _CRT_SPINCOUNT 4000 5 | #endif 6 | 7 | bool 8 | mtx_init(mtx_t *mtx) 9 | { 10 | 11 | #ifdef _WIN32 12 | if (!InitializeCriticalSectionAndSpinCount(&mtx->lock, _CRT_SPINCOUNT)) 13 | return (true); 14 | #elif (defined(JEMALLOC_OS_UNFAIR_LOCK)) 15 | mtx->lock = OS_UNFAIR_LOCK_INIT; 16 | #elif (defined(JEMALLOC_OSSPIN)) 17 | mtx->lock = 0; 18 | #else 19 | pthread_mutexattr_t attr; 20 | 21 | if (pthread_mutexattr_init(&attr) != 0) 22 | return (true); 23 | pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_DEFAULT); 24 | if (pthread_mutex_init(&mtx->lock, &attr) != 0) { 25 | pthread_mutexattr_destroy(&attr); 26 | return (true); 27 | } 28 | pthread_mutexattr_destroy(&attr); 29 | #endif 30 | return (false); 31 | } 32 | 33 | void 34 | mtx_fini(mtx_t *mtx) 35 | { 36 | 37 | #ifdef _WIN32 38 | #elif (defined(JEMALLOC_OS_UNFAIR_LOCK)) 39 | #elif (defined(JEMALLOC_OSSPIN)) 40 | #else 41 | pthread_mutex_destroy(&mtx->lock); 42 | #endif 43 | } 44 | 45 | void 46 | mtx_lock(mtx_t *mtx) 47 | { 48 | 49 | #ifdef _WIN32 50 | EnterCriticalSection(&mtx->lock); 51 | #elif (defined(JEMALLOC_OS_UNFAIR_LOCK)) 52 | os_unfair_lock_lock(&mtx->lock); 53 | #elif (defined(JEMALLOC_OSSPIN)) 54 | OSSpinLockLock(&mtx->lock); 55 | #else 56 | pthread_mutex_lock(&mtx->lock); 57 | #endif 58 | } 59 | 60 | void 61 | mtx_unlock(mtx_t *mtx) 62 | { 63 | 64 | #ifdef _WIN32 65 | LeaveCriticalSection(&mtx->lock); 66 | #elif (defined(JEMALLOC_OS_UNFAIR_LOCK)) 67 | os_unfair_lock_unlock(&mtx->lock); 68 | #elif (defined(JEMALLOC_OSSPIN)) 69 | OSSpinLockUnlock(&mtx->lock); 70 | #else 71 | pthread_mutex_unlock(&mtx->lock); 72 | #endif 73 | } 74 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/src/test.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | static unsigned test_count = 0; 4 | static test_status_t test_counts[test_status_count] = {0, 0, 0}; 5 | static test_status_t test_status = test_status_pass; 6 | static const char * test_name = ""; 7 | 8 | JEMALLOC_FORMAT_PRINTF(1, 2) 9 | void 10 | test_skip(const char *format, ...) 11 | { 12 | va_list ap; 13 | 14 | va_start(ap, format); 15 | malloc_vcprintf(NULL, NULL, format, ap); 16 | va_end(ap); 17 | malloc_printf("\n"); 18 | test_status = test_status_skip; 19 | } 20 | 21 | JEMALLOC_FORMAT_PRINTF(1, 2) 22 | void 23 | test_fail(const char *format, ...) 24 | { 25 | va_list ap; 26 | 27 | va_start(ap, format); 28 | malloc_vcprintf(NULL, NULL, format, ap); 29 | va_end(ap); 30 | malloc_printf("\n"); 31 | test_status = test_status_fail; 32 | } 33 | 34 | static const char * 35 | test_status_string(test_status_t test_status) 36 | { 37 | 38 | switch (test_status) { 39 | case test_status_pass: return "pass"; 40 | case test_status_skip: return "skip"; 41 | case test_status_fail: return "fail"; 42 | default: not_reached(); 43 | } 44 | } 45 | 46 | void 47 | p_test_init(const char *name) 48 | { 49 | 50 | test_count++; 51 | test_status = test_status_pass; 52 | test_name = name; 53 | } 54 | 55 | void 56 | p_test_fini(void) 57 | { 58 | 59 | test_counts[test_status]++; 60 | malloc_printf("%s: %s\n", test_name, test_status_string(test_status)); 61 | } 62 | 63 | static test_status_t 64 | p_test_impl(bool do_malloc_init, test_t *t, va_list ap) 65 | { 66 | test_status_t ret; 67 | 68 | if (do_malloc_init) { 69 | /* 70 | * Make sure initialization occurs prior to running tests. 71 | * Tests are special because they may use internal facilities 72 | * prior to triggering initialization as a side effect of 73 | * calling into the public API. 74 | */ 75 | if (nallocx(1, 0) == 0) { 76 | malloc_printf("Initialization error"); 77 | return (test_status_fail); 78 | } 79 | } 80 | 81 | ret = test_status_pass; 82 | for (; t != NULL; t = va_arg(ap, test_t *)) { 83 | t(); 84 | if (test_status > ret) 85 | ret = test_status; 86 | } 87 | 88 | malloc_printf("--- %s: %u/%u, %s: %u/%u, %s: %u/%u ---\n", 89 | test_status_string(test_status_pass), 90 | test_counts[test_status_pass], test_count, 91 | test_status_string(test_status_skip), 92 | test_counts[test_status_skip], test_count, 93 | test_status_string(test_status_fail), 94 | test_counts[test_status_fail], test_count); 95 | 96 | return (ret); 97 | } 98 | 99 | test_status_t 100 | p_test(test_t *t, ...) 101 | { 102 | test_status_t ret; 103 | va_list ap; 104 | 105 | ret = test_status_pass; 106 | va_start(ap, t); 107 | ret = p_test_impl(true, t, ap); 108 | va_end(ap); 109 | 110 | return (ret); 111 | } 112 | 113 | test_status_t 114 | p_test_no_malloc_init(test_t *t, ...) 115 | { 116 | test_status_t ret; 117 | va_list ap; 118 | 119 | ret = test_status_pass; 120 | va_start(ap, t); 121 | ret = p_test_impl(false, t, ap); 122 | va_end(ap); 123 | 124 | return (ret); 125 | } 126 | 127 | void 128 | p_test_fail(const char *prefix, const char *message) 129 | { 130 | 131 | malloc_cprintf(NULL, NULL, "%s%s\n", prefix, message); 132 | test_status = test_status_fail; 133 | } 134 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/src/thd.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | #ifdef _WIN32 4 | void 5 | thd_create(thd_t *thd, void *(*proc)(void *), void *arg) 6 | { 7 | LPTHREAD_START_ROUTINE routine = (LPTHREAD_START_ROUTINE)proc; 8 | *thd = CreateThread(NULL, 0, routine, arg, 0, NULL); 9 | if (*thd == NULL) 10 | test_fail("Error in CreateThread()\n"); 11 | } 12 | 13 | void 14 | thd_join(thd_t thd, void **ret) 15 | { 16 | 17 | if (WaitForSingleObject(thd, INFINITE) == WAIT_OBJECT_0 && ret) { 18 | DWORD exit_code; 19 | GetExitCodeThread(thd, (LPDWORD) &exit_code); 20 | *ret = (void *)(uintptr_t)exit_code; 21 | } 22 | } 23 | 24 | #else 25 | void 26 | thd_create(thd_t *thd, void *(*proc)(void *), void *arg) 27 | { 28 | 29 | if (pthread_create(thd, NULL, proc, arg) != 0) 30 | test_fail("Error in pthread_create()\n"); 31 | } 32 | 33 | void 34 | thd_join(thd_t thd, void **ret) 35 | { 36 | 37 | pthread_join(thd, ret); 38 | } 39 | #endif 40 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/src/timer.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | void 4 | timer_start(timedelta_t *timer) 5 | { 6 | 7 | nstime_init(&timer->t0, 0); 8 | nstime_update(&timer->t0); 9 | } 10 | 11 | void 12 | timer_stop(timedelta_t *timer) 13 | { 14 | 15 | nstime_copy(&timer->t1, &timer->t0); 16 | nstime_update(&timer->t1); 17 | } 18 | 19 | uint64_t 20 | timer_usec(const timedelta_t *timer) 21 | { 22 | nstime_t delta; 23 | 24 | nstime_copy(&delta, &timer->t1); 25 | nstime_subtract(&delta, &timer->t0); 26 | return (nstime_ns(&delta) / 1000); 27 | } 28 | 29 | void 30 | timer_ratio(timedelta_t *a, timedelta_t *b, char *buf, size_t buflen) 31 | { 32 | uint64_t t0 = timer_usec(a); 33 | uint64_t t1 = timer_usec(b); 34 | uint64_t mult; 35 | size_t i = 0; 36 | size_t j, n; 37 | 38 | /* Whole. */ 39 | n = malloc_snprintf(&buf[i], buflen-i, "%"FMTu64, t0 / t1); 40 | i += n; 41 | if (i >= buflen) 42 | return; 43 | mult = 1; 44 | for (j = 0; j < n; j++) 45 | mult *= 10; 46 | 47 | /* Decimal. */ 48 | n = malloc_snprintf(&buf[i], buflen-i, "."); 49 | i += n; 50 | 51 | /* Fraction. */ 52 | while (i < buflen-1) { 53 | uint64_t round = (i+1 == buflen-1 && ((t0 * mult * 10 / t1) % 10 54 | >= 5)) ? 1 : 0; 55 | n = malloc_snprintf(&buf[i], buflen-i, 56 | "%"FMTu64, (t0 * mult / t1) % 10 + round); 57 | i += n; 58 | mult *= 10; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/test.sh.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | case @abi@ in 4 | macho) 5 | export DYLD_FALLBACK_LIBRARY_PATH="@objroot@lib" 6 | ;; 7 | pecoff) 8 | export PATH="${PATH}:@objroot@lib" 9 | ;; 10 | *) 11 | ;; 12 | esac 13 | 14 | # Make a copy of the @JEMALLOC_CPREFIX@MALLOC_CONF passed in to this script, so 15 | # it can be repeatedly concatenated with per test settings. 16 | export MALLOC_CONF_ALL=${@JEMALLOC_CPREFIX@MALLOC_CONF} 17 | # Concatenate the individual test's MALLOC_CONF and MALLOC_CONF_ALL. 18 | export_malloc_conf() { 19 | if [ "x${MALLOC_CONF}" != "x" -a "x${MALLOC_CONF_ALL}" != "x" ] ; then 20 | export @JEMALLOC_CPREFIX@MALLOC_CONF="${MALLOC_CONF},${MALLOC_CONF_ALL}" 21 | else 22 | export @JEMALLOC_CPREFIX@MALLOC_CONF="${MALLOC_CONF}${MALLOC_CONF_ALL}" 23 | fi 24 | } 25 | 26 | # Corresponds to test_status_t. 27 | pass_code=0 28 | skip_code=1 29 | fail_code=2 30 | 31 | pass_count=0 32 | skip_count=0 33 | fail_count=0 34 | for t in $@; do 35 | if [ $pass_count -ne 0 -o $skip_count -ne 0 -o $fail_count != 0 ] ; then 36 | echo 37 | fi 38 | echo "=== ${t} ===" 39 | if [ -e "@srcroot@${t}.sh" ] ; then 40 | # Source the shell script corresponding to the test in a subshell and 41 | # execute the test. This allows the shell script to set MALLOC_CONF, which 42 | # is then used to set @JEMALLOC_CPREFIX@MALLOC_CONF (thus allowing the 43 | # per test shell script to ignore the @JEMALLOC_CPREFIX@ detail). 44 | $(enable_fill=@enable_fill@ \ 45 | enable_prof=@enable_prof@ \ 46 | enable_tcache=@enable_tcache@ \ 47 | . @srcroot@${t}.sh && \ 48 | export_malloc_conf && \ 49 | ${t}@exe@ @abs_srcroot@ @abs_objroot@) 50 | else 51 | $(export MALLOC_CONF= && \ 52 | export_malloc_conf && 53 | ${t}@exe@ @abs_srcroot@ @abs_objroot@) 54 | fi 55 | result_code=$? 56 | case ${result_code} in 57 | ${pass_code}) 58 | pass_count=$((pass_count+1)) 59 | ;; 60 | ${skip_code}) 61 | skip_count=$((skip_count+1)) 62 | ;; 63 | ${fail_code}) 64 | fail_count=$((fail_count+1)) 65 | ;; 66 | *) 67 | echo "Test harness error" 1>&2 68 | exit 1 69 | esac 70 | done 71 | 72 | total_count=`expr ${pass_count} + ${skip_count} + ${fail_count}` 73 | echo 74 | echo "Test suite summary: pass: ${pass_count}/${total_count}, skip: ${skip_count}/${total_count}, fail: ${fail_count}/${total_count}" 75 | 76 | if [ ${fail_count} -eq 0 ] ; then 77 | exit 0 78 | else 79 | exit 1 80 | fi 81 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/unit/a0.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | TEST_BEGIN(test_a0) 4 | { 5 | void *p; 6 | 7 | p = a0malloc(1); 8 | assert_ptr_not_null(p, "Unexpected a0malloc() error"); 9 | a0dalloc(p); 10 | } 11 | TEST_END 12 | 13 | int 14 | main(void) 15 | { 16 | 17 | return (test_no_malloc_init( 18 | test_a0)); 19 | } 20 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/unit/arena_reset.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "x${enable_prof}" = "x1" ] ; then 4 | export MALLOC_CONF="prof:true,lg_prof_sample:0" 5 | fi 6 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/unit/decay.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | export MALLOC_CONF="purge:decay,decay_time:1" 4 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/unit/extent_quantize.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | TEST_BEGIN(test_huge_extent_size) { 4 | unsigned nhchunks, i; 5 | size_t sz, extent_size_prev, ceil_prev; 6 | size_t mib[4]; 7 | size_t miblen = sizeof(mib) / sizeof(size_t); 8 | 9 | /* 10 | * Iterate over all huge size classes, get their extent sizes, and 11 | * verify that the quantized size is the same as the extent size. 12 | */ 13 | 14 | sz = sizeof(unsigned); 15 | assert_d_eq(mallctl("arenas.nhchunks", (void *)&nhchunks, &sz, NULL, 16 | 0), 0, "Unexpected mallctl failure"); 17 | 18 | assert_d_eq(mallctlnametomib("arenas.hchunk.0.size", mib, &miblen), 0, 19 | "Unexpected mallctlnametomib failure"); 20 | for (i = 0; i < nhchunks; i++) { 21 | size_t extent_size, floor, ceil; 22 | 23 | 24 | mib[2] = i; 25 | sz = sizeof(size_t); 26 | assert_d_eq(mallctlbymib(mib, miblen, (void *)&extent_size, 27 | &sz, NULL, 0), 0, "Unexpected mallctlbymib failure"); 28 | floor = extent_size_quantize_floor(extent_size); 29 | ceil = extent_size_quantize_ceil(extent_size); 30 | 31 | assert_zu_eq(extent_size, floor, 32 | "Extent quantization should be a no-op for precise size " 33 | "(extent_size=%zu)", extent_size); 34 | assert_zu_eq(extent_size, ceil, 35 | "Extent quantization should be a no-op for precise size " 36 | "(extent_size=%zu)", extent_size); 37 | 38 | if (i > 0) { 39 | assert_zu_eq(extent_size_prev, 40 | extent_size_quantize_floor(extent_size - PAGE), 41 | "Floor should be a precise size"); 42 | if (extent_size_prev < ceil_prev) { 43 | assert_zu_eq(ceil_prev, extent_size, 44 | "Ceiling should be a precise size " 45 | "(extent_size_prev=%zu, ceil_prev=%zu, " 46 | "extent_size=%zu)", extent_size_prev, 47 | ceil_prev, extent_size); 48 | } 49 | } 50 | if (i + 1 < nhchunks) { 51 | extent_size_prev = floor; 52 | ceil_prev = extent_size_quantize_ceil(extent_size + 53 | PAGE); 54 | } 55 | } 56 | } 57 | TEST_END 58 | 59 | TEST_BEGIN(test_monotonic) { 60 | #define SZ_MAX ZU(4 * 1024 * 1024) 61 | unsigned i; 62 | size_t floor_prev, ceil_prev; 63 | 64 | floor_prev = 0; 65 | ceil_prev = 0; 66 | for (i = 1; i <= SZ_MAX >> LG_PAGE; i++) { 67 | size_t extent_size, floor, ceil; 68 | 69 | extent_size = i << LG_PAGE; 70 | floor = extent_size_quantize_floor(extent_size); 71 | ceil = extent_size_quantize_ceil(extent_size); 72 | 73 | assert_zu_le(floor, extent_size, 74 | "Floor should be <= (floor=%zu, extent_size=%zu, ceil=%zu)", 75 | floor, extent_size, ceil); 76 | assert_zu_ge(ceil, extent_size, 77 | "Ceiling should be >= (floor=%zu, extent_size=%zu, " 78 | "ceil=%zu)", floor, extent_size, ceil); 79 | 80 | assert_zu_le(floor_prev, floor, "Floor should be monotonic " 81 | "(floor_prev=%zu, floor=%zu, extent_size=%zu, ceil=%zu)", 82 | floor_prev, floor, extent_size, ceil); 83 | assert_zu_le(ceil_prev, ceil, "Ceiling should be monotonic " 84 | "(floor=%zu, extent_size=%zu, ceil_prev=%zu, ceil=%zu)", 85 | floor, extent_size, ceil_prev, ceil); 86 | 87 | floor_prev = floor; 88 | ceil_prev = ceil; 89 | } 90 | } 91 | TEST_END 92 | 93 | int 94 | main(void) { 95 | return test( 96 | test_huge_extent_size, 97 | test_monotonic); 98 | } 99 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/unit/fork.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | #ifndef _WIN32 4 | #include 5 | #endif 6 | 7 | TEST_BEGIN(test_fork) 8 | { 9 | #ifndef _WIN32 10 | void *p; 11 | pid_t pid; 12 | 13 | p = malloc(1); 14 | assert_ptr_not_null(p, "Unexpected malloc() failure"); 15 | 16 | pid = fork(); 17 | 18 | free(p); 19 | 20 | p = malloc(64); 21 | assert_ptr_not_null(p, "Unexpected malloc() failure"); 22 | free(p); 23 | 24 | if (pid == -1) { 25 | /* Error. */ 26 | test_fail("Unexpected fork() failure"); 27 | } else if (pid == 0) { 28 | /* Child. */ 29 | _exit(0); 30 | } else { 31 | int status; 32 | 33 | /* Parent. */ 34 | while (true) { 35 | if (waitpid(pid, &status, 0) == -1) 36 | test_fail("Unexpected waitpid() failure"); 37 | if (WIFSIGNALED(status)) { 38 | test_fail("Unexpected child termination due to " 39 | "signal %d", WTERMSIG(status)); 40 | break; 41 | } 42 | if (WIFEXITED(status)) { 43 | if (WEXITSTATUS(status) != 0) { 44 | test_fail( 45 | "Unexpected child exit value %d", 46 | WEXITSTATUS(status)); 47 | } 48 | break; 49 | } 50 | } 51 | } 52 | #else 53 | test_skip("fork(2) is irrelevant to Windows"); 54 | #endif 55 | } 56 | TEST_END 57 | 58 | int 59 | main(void) 60 | { 61 | 62 | return (test( 63 | test_fork)); 64 | } 65 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/unit/junk.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "x${enable_fill}" = "x1" ] ; then 4 | export MALLOC_CONF="abort:false,zero:false,redzone:true,quarantine:0,junk:true" 5 | fi 6 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/unit/junk_alloc.c: -------------------------------------------------------------------------------- 1 | #include "junk.c" 2 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/unit/junk_alloc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "x${enable_fill}" = "x1" ] ; then 4 | export MALLOC_CONF="abort:false,zero:false,redzone:true,quarantine:0,junk:alloc" 5 | fi 6 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/unit/junk_free.c: -------------------------------------------------------------------------------- 1 | #include "junk.c" 2 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/unit/junk_free.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "x${enable_fill}" = "x1" ] ; then 4 | export MALLOC_CONF="abort:false,zero:false,redzone:true,quarantine:0,junk:free" 5 | fi 6 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/unit/lg_chunk.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | TEST_BEGIN(test_lg_chunk_clamp) 4 | { 5 | void *p; 6 | 7 | p = mallocx(1, 0); 8 | assert_ptr_not_null(p, "Unexpected mallocx() failure"); 9 | dallocx(p, 0); 10 | } 11 | TEST_END 12 | 13 | int 14 | main(void) 15 | { 16 | 17 | return (test( 18 | test_lg_chunk_clamp)); 19 | } 20 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/unit/lg_chunk.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Make sure that opt.lg_chunk clamping is sufficient. In practice, this test 4 | # program will fail a debug assertion during initialization and abort (rather 5 | # than the test soft-failing) if clamping is insufficient. 6 | export MALLOC_CONF="lg_chunk:0" 7 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/unit/mq.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | #define NSENDERS 3 4 | #define NMSGS 100000 5 | 6 | typedef struct mq_msg_s mq_msg_t; 7 | struct mq_msg_s { 8 | mq_msg(mq_msg_t) link; 9 | }; 10 | mq_gen(static, mq_, mq_t, mq_msg_t, link) 11 | 12 | TEST_BEGIN(test_mq_basic) 13 | { 14 | mq_t mq; 15 | mq_msg_t msg; 16 | 17 | assert_false(mq_init(&mq), "Unexpected mq_init() failure"); 18 | assert_u_eq(mq_count(&mq), 0, "mq should be empty"); 19 | assert_ptr_null(mq_tryget(&mq), 20 | "mq_tryget() should fail when the queue is empty"); 21 | 22 | mq_put(&mq, &msg); 23 | assert_u_eq(mq_count(&mq), 1, "mq should contain one message"); 24 | assert_ptr_eq(mq_tryget(&mq), &msg, "mq_tryget() should return msg"); 25 | 26 | mq_put(&mq, &msg); 27 | assert_ptr_eq(mq_get(&mq), &msg, "mq_get() should return msg"); 28 | 29 | mq_fini(&mq); 30 | } 31 | TEST_END 32 | 33 | static void * 34 | thd_receiver_start(void *arg) 35 | { 36 | mq_t *mq = (mq_t *)arg; 37 | unsigned i; 38 | 39 | for (i = 0; i < (NSENDERS * NMSGS); i++) { 40 | mq_msg_t *msg = mq_get(mq); 41 | assert_ptr_not_null(msg, "mq_get() should never return NULL"); 42 | dallocx(msg, 0); 43 | } 44 | return (NULL); 45 | } 46 | 47 | static void * 48 | thd_sender_start(void *arg) 49 | { 50 | mq_t *mq = (mq_t *)arg; 51 | unsigned i; 52 | 53 | for (i = 0; i < NMSGS; i++) { 54 | mq_msg_t *msg; 55 | void *p; 56 | p = mallocx(sizeof(mq_msg_t), 0); 57 | assert_ptr_not_null(p, "Unexpected mallocx() failure"); 58 | msg = (mq_msg_t *)p; 59 | mq_put(mq, msg); 60 | } 61 | return (NULL); 62 | } 63 | 64 | TEST_BEGIN(test_mq_threaded) 65 | { 66 | mq_t mq; 67 | thd_t receiver; 68 | thd_t senders[NSENDERS]; 69 | unsigned i; 70 | 71 | assert_false(mq_init(&mq), "Unexpected mq_init() failure"); 72 | 73 | thd_create(&receiver, thd_receiver_start, (void *)&mq); 74 | for (i = 0; i < NSENDERS; i++) 75 | thd_create(&senders[i], thd_sender_start, (void *)&mq); 76 | 77 | thd_join(receiver, NULL); 78 | for (i = 0; i < NSENDERS; i++) 79 | thd_join(senders[i], NULL); 80 | 81 | mq_fini(&mq); 82 | } 83 | TEST_END 84 | 85 | int 86 | main(void) 87 | { 88 | 89 | return (test( 90 | test_mq_basic, 91 | test_mq_threaded)); 92 | } 93 | 94 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/unit/mtx.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | #define NTHREADS 2 4 | #define NINCRS 2000000 5 | 6 | TEST_BEGIN(test_mtx_basic) 7 | { 8 | mtx_t mtx; 9 | 10 | assert_false(mtx_init(&mtx), "Unexpected mtx_init() failure"); 11 | mtx_lock(&mtx); 12 | mtx_unlock(&mtx); 13 | mtx_fini(&mtx); 14 | } 15 | TEST_END 16 | 17 | typedef struct { 18 | mtx_t mtx; 19 | unsigned x; 20 | } thd_start_arg_t; 21 | 22 | static void * 23 | thd_start(void *varg) 24 | { 25 | thd_start_arg_t *arg = (thd_start_arg_t *)varg; 26 | unsigned i; 27 | 28 | for (i = 0; i < NINCRS; i++) { 29 | mtx_lock(&arg->mtx); 30 | arg->x++; 31 | mtx_unlock(&arg->mtx); 32 | } 33 | return (NULL); 34 | } 35 | 36 | TEST_BEGIN(test_mtx_race) 37 | { 38 | thd_start_arg_t arg; 39 | thd_t thds[NTHREADS]; 40 | unsigned i; 41 | 42 | assert_false(mtx_init(&arg.mtx), "Unexpected mtx_init() failure"); 43 | arg.x = 0; 44 | for (i = 0; i < NTHREADS; i++) 45 | thd_create(&thds[i], thd_start, (void *)&arg); 46 | for (i = 0; i < NTHREADS; i++) 47 | thd_join(thds[i], NULL); 48 | assert_u_eq(arg.x, NTHREADS * NINCRS, 49 | "Race-related counter corruption"); 50 | } 51 | TEST_END 52 | 53 | int 54 | main(void) 55 | { 56 | 57 | return (test( 58 | test_mtx_basic, 59 | test_mtx_race)); 60 | } 61 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/unit/pack.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Use smallest possible chunk size. Immediately purge to minimize 4 | # fragmentation. 5 | export MALLOC_CONF="lg_chunk:0,lg_dirty_mult:-1,decay_time:-1" 6 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/unit/pages.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | TEST_BEGIN(test_pages_huge) 4 | { 5 | bool commit; 6 | void *pages; 7 | 8 | commit = true; 9 | pages = pages_map(NULL, PAGE, &commit); 10 | assert_ptr_not_null(pages, "Unexpected pages_map() error"); 11 | 12 | assert_false(pages_huge(pages, PAGE), 13 | "Unexpected pages_huge() result"); 14 | assert_false(pages_nohuge(pages, PAGE), 15 | "Unexpected pages_nohuge() result"); 16 | 17 | pages_unmap(pages, PAGE); 18 | } 19 | TEST_END 20 | 21 | int 22 | main(void) 23 | { 24 | 25 | return (test( 26 | test_pages_huge)); 27 | } 28 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/unit/prof_accum.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | #define NTHREADS 4 4 | #define NALLOCS_PER_THREAD 50 5 | #define DUMP_INTERVAL 1 6 | #define BT_COUNT_CHECK_INTERVAL 5 7 | 8 | static int 9 | prof_dump_open_intercept(bool propagate_err, const char *filename) 10 | { 11 | int fd; 12 | 13 | fd = open("/dev/null", O_WRONLY); 14 | assert_d_ne(fd, -1, "Unexpected open() failure"); 15 | 16 | return (fd); 17 | } 18 | 19 | static void * 20 | alloc_from_permuted_backtrace(unsigned thd_ind, unsigned iteration) 21 | { 22 | 23 | return (btalloc(1, thd_ind*NALLOCS_PER_THREAD + iteration)); 24 | } 25 | 26 | static void * 27 | thd_start(void *varg) 28 | { 29 | unsigned thd_ind = *(unsigned *)varg; 30 | size_t bt_count_prev, bt_count; 31 | unsigned i_prev, i; 32 | 33 | i_prev = 0; 34 | bt_count_prev = 0; 35 | for (i = 0; i < NALLOCS_PER_THREAD; i++) { 36 | void *p = alloc_from_permuted_backtrace(thd_ind, i); 37 | dallocx(p, 0); 38 | if (i % DUMP_INTERVAL == 0) { 39 | assert_d_eq(mallctl("prof.dump", NULL, NULL, NULL, 0), 40 | 0, "Unexpected error while dumping heap profile"); 41 | } 42 | 43 | if (i % BT_COUNT_CHECK_INTERVAL == 0 || 44 | i+1 == NALLOCS_PER_THREAD) { 45 | bt_count = prof_bt_count(); 46 | assert_zu_le(bt_count_prev+(i-i_prev), bt_count, 47 | "Expected larger backtrace count increase"); 48 | i_prev = i; 49 | bt_count_prev = bt_count; 50 | } 51 | } 52 | 53 | return (NULL); 54 | } 55 | 56 | TEST_BEGIN(test_idump) 57 | { 58 | bool active; 59 | thd_t thds[NTHREADS]; 60 | unsigned thd_args[NTHREADS]; 61 | unsigned i; 62 | 63 | test_skip_if(!config_prof); 64 | 65 | active = true; 66 | assert_d_eq(mallctl("prof.active", NULL, NULL, (void *)&active, 67 | sizeof(active)), 0, 68 | "Unexpected mallctl failure while activating profiling"); 69 | 70 | prof_dump_open = prof_dump_open_intercept; 71 | 72 | for (i = 0; i < NTHREADS; i++) { 73 | thd_args[i] = i; 74 | thd_create(&thds[i], thd_start, (void *)&thd_args[i]); 75 | } 76 | for (i = 0; i < NTHREADS; i++) 77 | thd_join(thds[i], NULL); 78 | } 79 | TEST_END 80 | 81 | int 82 | main(void) 83 | { 84 | 85 | return (test( 86 | test_idump)); 87 | } 88 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/unit/prof_accum.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "x${enable_prof}" = "x1" ] ; then 4 | export MALLOC_CONF="prof:true,prof_accum:true,prof_active:false,lg_prof_sample:0" 5 | fi 6 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/unit/prof_active.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "x${enable_prof}" = "x1" ] ; then 4 | export MALLOC_CONF="prof:true,prof_thread_active_init:false,lg_prof_sample:0" 5 | fi 6 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/unit/prof_gdump.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | static bool did_prof_dump_open; 4 | 5 | static int 6 | prof_dump_open_intercept(bool propagate_err, const char *filename) 7 | { 8 | int fd; 9 | 10 | did_prof_dump_open = true; 11 | 12 | fd = open("/dev/null", O_WRONLY); 13 | assert_d_ne(fd, -1, "Unexpected open() failure"); 14 | 15 | return (fd); 16 | } 17 | 18 | TEST_BEGIN(test_gdump) 19 | { 20 | bool active, gdump, gdump_old; 21 | void *p, *q, *r, *s; 22 | size_t sz; 23 | 24 | test_skip_if(!config_prof); 25 | 26 | active = true; 27 | assert_d_eq(mallctl("prof.active", NULL, NULL, (void *)&active, 28 | sizeof(active)), 0, 29 | "Unexpected mallctl failure while activating profiling"); 30 | 31 | prof_dump_open = prof_dump_open_intercept; 32 | 33 | did_prof_dump_open = false; 34 | p = mallocx(chunksize, 0); 35 | assert_ptr_not_null(p, "Unexpected mallocx() failure"); 36 | assert_true(did_prof_dump_open, "Expected a profile dump"); 37 | 38 | did_prof_dump_open = false; 39 | q = mallocx(chunksize, 0); 40 | assert_ptr_not_null(q, "Unexpected mallocx() failure"); 41 | assert_true(did_prof_dump_open, "Expected a profile dump"); 42 | 43 | gdump = false; 44 | sz = sizeof(gdump_old); 45 | assert_d_eq(mallctl("prof.gdump", (void *)&gdump_old, &sz, 46 | (void *)&gdump, sizeof(gdump)), 0, 47 | "Unexpected mallctl failure while disabling prof.gdump"); 48 | assert(gdump_old); 49 | did_prof_dump_open = false; 50 | r = mallocx(chunksize, 0); 51 | assert_ptr_not_null(q, "Unexpected mallocx() failure"); 52 | assert_false(did_prof_dump_open, "Unexpected profile dump"); 53 | 54 | gdump = true; 55 | sz = sizeof(gdump_old); 56 | assert_d_eq(mallctl("prof.gdump", (void *)&gdump_old, &sz, 57 | (void *)&gdump, sizeof(gdump)), 0, 58 | "Unexpected mallctl failure while enabling prof.gdump"); 59 | assert(!gdump_old); 60 | did_prof_dump_open = false; 61 | s = mallocx(chunksize, 0); 62 | assert_ptr_not_null(q, "Unexpected mallocx() failure"); 63 | assert_true(did_prof_dump_open, "Expected a profile dump"); 64 | 65 | dallocx(p, 0); 66 | dallocx(q, 0); 67 | dallocx(r, 0); 68 | dallocx(s, 0); 69 | } 70 | TEST_END 71 | 72 | int 73 | main(void) 74 | { 75 | 76 | return (test( 77 | test_gdump)); 78 | } 79 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/unit/prof_gdump.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "x${enable_prof}" = "x1" ] ; then 4 | export MALLOC_CONF="prof:true,prof_active:false,prof_gdump:true" 5 | fi 6 | 7 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/unit/prof_idump.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | static bool did_prof_dump_open; 4 | 5 | static int 6 | prof_dump_open_intercept(bool propagate_err, const char *filename) 7 | { 8 | int fd; 9 | 10 | did_prof_dump_open = true; 11 | 12 | fd = open("/dev/null", O_WRONLY); 13 | assert_d_ne(fd, -1, "Unexpected open() failure"); 14 | 15 | return (fd); 16 | } 17 | 18 | TEST_BEGIN(test_idump) 19 | { 20 | bool active; 21 | void *p; 22 | 23 | test_skip_if(!config_prof); 24 | 25 | active = true; 26 | assert_d_eq(mallctl("prof.active", NULL, NULL, (void *)&active, 27 | sizeof(active)), 0, 28 | "Unexpected mallctl failure while activating profiling"); 29 | 30 | prof_dump_open = prof_dump_open_intercept; 31 | 32 | did_prof_dump_open = false; 33 | p = mallocx(1, 0); 34 | assert_ptr_not_null(p, "Unexpected mallocx() failure"); 35 | dallocx(p, 0); 36 | assert_true(did_prof_dump_open, "Expected a profile dump"); 37 | } 38 | TEST_END 39 | 40 | int 41 | main(void) 42 | { 43 | 44 | return (test( 45 | test_idump)); 46 | } 47 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/unit/prof_idump.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "x${enable_prof}" = "x1" ] ; then 4 | export MALLOC_CONF="prof:true,prof_accum:true,prof_active:false,lg_prof_sample:0,lg_prof_interval:0" 5 | fi 6 | 7 | 8 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/unit/prof_reset.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "x${enable_prof}" = "x1" ] ; then 4 | export MALLOC_CONF="prof:true,prof_active:false,lg_prof_sample:0" 5 | fi 6 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/unit/prof_tctx.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "x${enable_prof}" = "x1" ] ; then 4 | export MALLOC_CONF="prof:true,lg_prof_sample:0" 5 | fi 6 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/unit/prof_thread_name.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "x${enable_prof}" = "x1" ] ; then 4 | export MALLOC_CONF="prof:true,prof_active:false" 5 | fi 6 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/unit/quarantine.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | /* Keep in sync with definition in quarantine.sh. */ 4 | #define QUARANTINE_SIZE 8192 5 | 6 | void 7 | quarantine_clear(void) 8 | { 9 | void *p; 10 | 11 | p = mallocx(QUARANTINE_SIZE*2, 0); 12 | assert_ptr_not_null(p, "Unexpected mallocx() failure"); 13 | dallocx(p, 0); 14 | } 15 | 16 | TEST_BEGIN(test_quarantine) 17 | { 18 | #define SZ ZU(256) 19 | #define NQUARANTINED (QUARANTINE_SIZE/SZ) 20 | void *quarantined[NQUARANTINED+1]; 21 | size_t i, j; 22 | 23 | test_skip_if(!config_fill); 24 | 25 | assert_zu_eq(nallocx(SZ, 0), SZ, 26 | "SZ=%zu does not precisely equal a size class", SZ); 27 | 28 | quarantine_clear(); 29 | 30 | /* 31 | * Allocate enough regions to completely fill the quarantine, plus one 32 | * more. The last iteration occurs with a completely full quarantine, 33 | * but no regions should be drained from the quarantine until the last 34 | * deallocation occurs. Therefore no region recycling should occur 35 | * until after this loop completes. 36 | */ 37 | for (i = 0; i < NQUARANTINED+1; i++) { 38 | void *p = mallocx(SZ, 0); 39 | assert_ptr_not_null(p, "Unexpected mallocx() failure"); 40 | quarantined[i] = p; 41 | dallocx(p, 0); 42 | for (j = 0; j < i; j++) { 43 | assert_ptr_ne(p, quarantined[j], 44 | "Quarantined region recycled too early; " 45 | "i=%zu, j=%zu", i, j); 46 | } 47 | } 48 | #undef NQUARANTINED 49 | #undef SZ 50 | } 51 | TEST_END 52 | 53 | static bool detected_redzone_corruption; 54 | 55 | static void 56 | arena_redzone_corruption_replacement(void *ptr, size_t usize, bool after, 57 | size_t offset, uint8_t byte) 58 | { 59 | 60 | detected_redzone_corruption = true; 61 | } 62 | 63 | TEST_BEGIN(test_quarantine_redzone) 64 | { 65 | char *s; 66 | arena_redzone_corruption_t *arena_redzone_corruption_orig; 67 | 68 | test_skip_if(!config_fill); 69 | 70 | arena_redzone_corruption_orig = arena_redzone_corruption; 71 | arena_redzone_corruption = arena_redzone_corruption_replacement; 72 | 73 | /* Test underflow. */ 74 | detected_redzone_corruption = false; 75 | s = (char *)mallocx(1, 0); 76 | assert_ptr_not_null((void *)s, "Unexpected mallocx() failure"); 77 | s[-1] = 0xbb; 78 | dallocx(s, 0); 79 | assert_true(detected_redzone_corruption, 80 | "Did not detect redzone corruption"); 81 | 82 | /* Test overflow. */ 83 | detected_redzone_corruption = false; 84 | s = (char *)mallocx(1, 0); 85 | assert_ptr_not_null((void *)s, "Unexpected mallocx() failure"); 86 | s[sallocx(s, 0)] = 0xbb; 87 | dallocx(s, 0); 88 | assert_true(detected_redzone_corruption, 89 | "Did not detect redzone corruption"); 90 | 91 | arena_redzone_corruption = arena_redzone_corruption_orig; 92 | } 93 | TEST_END 94 | 95 | int 96 | main(void) 97 | { 98 | 99 | return (test( 100 | test_quarantine, 101 | test_quarantine_redzone)); 102 | } 103 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/unit/quarantine.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Keep in sync with definition in quarantine.c. 4 | export QUARANTINE_SIZE=8192 5 | 6 | if [ "x${enable_fill}" = "x1" ] ; then 7 | export MALLOC_CONF="abort:false,junk:true,redzone:true,quarantine:${QUARANTINE_SIZE}" 8 | fi 9 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/unit/smoothstep.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | static const uint64_t smoothstep_tab[] = { 4 | #define STEP(step, h, x, y) \ 5 | h, 6 | SMOOTHSTEP 7 | #undef STEP 8 | }; 9 | 10 | TEST_BEGIN(test_smoothstep_integral) 11 | { 12 | uint64_t sum, min, max; 13 | unsigned i; 14 | 15 | /* 16 | * The integral of smoothstep in the [0..1] range equals 1/2. Verify 17 | * that the fixed point representation's integral is no more than 18 | * rounding error distant from 1/2. Regarding rounding, each table 19 | * element is rounded down to the nearest fixed point value, so the 20 | * integral may be off by as much as SMOOTHSTEP_NSTEPS ulps. 21 | */ 22 | sum = 0; 23 | for (i = 0; i < SMOOTHSTEP_NSTEPS; i++) 24 | sum += smoothstep_tab[i]; 25 | 26 | max = (KQU(1) << (SMOOTHSTEP_BFP-1)) * (SMOOTHSTEP_NSTEPS+1); 27 | min = max - SMOOTHSTEP_NSTEPS; 28 | 29 | assert_u64_ge(sum, min, 30 | "Integral too small, even accounting for truncation"); 31 | assert_u64_le(sum, max, "Integral exceeds 1/2"); 32 | if (false) { 33 | malloc_printf("%"FMTu64" ulps under 1/2 (limit %d)\n", 34 | max - sum, SMOOTHSTEP_NSTEPS); 35 | } 36 | } 37 | TEST_END 38 | 39 | TEST_BEGIN(test_smoothstep_monotonic) 40 | { 41 | uint64_t prev_h; 42 | unsigned i; 43 | 44 | /* 45 | * The smoothstep function is monotonic in [0..1], i.e. its slope is 46 | * non-negative. In practice we want to parametrize table generation 47 | * such that piecewise slope is greater than zero, but do not require 48 | * that here. 49 | */ 50 | prev_h = 0; 51 | for (i = 0; i < SMOOTHSTEP_NSTEPS; i++) { 52 | uint64_t h = smoothstep_tab[i]; 53 | assert_u64_ge(h, prev_h, "Piecewise non-monotonic, i=%u", i); 54 | prev_h = h; 55 | } 56 | assert_u64_eq(smoothstep_tab[SMOOTHSTEP_NSTEPS-1], 57 | (KQU(1) << SMOOTHSTEP_BFP), "Last step must equal 1"); 58 | } 59 | TEST_END 60 | 61 | TEST_BEGIN(test_smoothstep_slope) 62 | { 63 | uint64_t prev_h, prev_delta; 64 | unsigned i; 65 | 66 | /* 67 | * The smoothstep slope strictly increases until x=0.5, and then 68 | * strictly decreases until x=1.0. Verify the slightly weaker 69 | * requirement of monotonicity, so that inadequate table precision does 70 | * not cause false test failures. 71 | */ 72 | prev_h = 0; 73 | prev_delta = 0; 74 | for (i = 0; i < SMOOTHSTEP_NSTEPS / 2 + SMOOTHSTEP_NSTEPS % 2; i++) { 75 | uint64_t h = smoothstep_tab[i]; 76 | uint64_t delta = h - prev_h; 77 | assert_u64_ge(delta, prev_delta, 78 | "Slope must monotonically increase in 0.0 <= x <= 0.5, " 79 | "i=%u", i); 80 | prev_h = h; 81 | prev_delta = delta; 82 | } 83 | 84 | prev_h = KQU(1) << SMOOTHSTEP_BFP; 85 | prev_delta = 0; 86 | for (i = SMOOTHSTEP_NSTEPS-1; i >= SMOOTHSTEP_NSTEPS / 2; i--) { 87 | uint64_t h = smoothstep_tab[i]; 88 | uint64_t delta = prev_h - h; 89 | assert_u64_ge(delta, prev_delta, 90 | "Slope must monotonically decrease in 0.5 <= x <= 1.0, " 91 | "i=%u", i); 92 | prev_h = h; 93 | prev_delta = delta; 94 | } 95 | } 96 | TEST_END 97 | 98 | int 99 | main(void) 100 | { 101 | 102 | return (test( 103 | test_smoothstep_integral, 104 | test_smoothstep_monotonic, 105 | test_smoothstep_slope)); 106 | } 107 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/unit/ticker.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | TEST_BEGIN(test_ticker_tick) 4 | { 5 | #define NREPS 2 6 | #define NTICKS 3 7 | ticker_t ticker; 8 | int32_t i, j; 9 | 10 | ticker_init(&ticker, NTICKS); 11 | for (i = 0; i < NREPS; i++) { 12 | for (j = 0; j < NTICKS; j++) { 13 | assert_u_eq(ticker_read(&ticker), NTICKS - j, 14 | "Unexpected ticker value (i=%d, j=%d)", i, j); 15 | assert_false(ticker_tick(&ticker), 16 | "Unexpected ticker fire (i=%d, j=%d)", i, j); 17 | } 18 | assert_u32_eq(ticker_read(&ticker), 0, 19 | "Expected ticker depletion"); 20 | assert_true(ticker_tick(&ticker), 21 | "Expected ticker fire (i=%d)", i); 22 | assert_u32_eq(ticker_read(&ticker), NTICKS, 23 | "Expected ticker reset"); 24 | } 25 | #undef NTICKS 26 | } 27 | TEST_END 28 | 29 | TEST_BEGIN(test_ticker_ticks) 30 | { 31 | #define NTICKS 3 32 | ticker_t ticker; 33 | 34 | ticker_init(&ticker, NTICKS); 35 | 36 | assert_u_eq(ticker_read(&ticker), NTICKS, "Unexpected ticker value"); 37 | assert_false(ticker_ticks(&ticker, NTICKS), "Unexpected ticker fire"); 38 | assert_u_eq(ticker_read(&ticker), 0, "Unexpected ticker value"); 39 | assert_true(ticker_ticks(&ticker, NTICKS), "Expected ticker fire"); 40 | assert_u_eq(ticker_read(&ticker), NTICKS, "Unexpected ticker value"); 41 | 42 | assert_true(ticker_ticks(&ticker, NTICKS + 1), "Expected ticker fire"); 43 | assert_u_eq(ticker_read(&ticker), NTICKS, "Unexpected ticker value"); 44 | #undef NTICKS 45 | } 46 | TEST_END 47 | 48 | TEST_BEGIN(test_ticker_copy) 49 | { 50 | #define NTICKS 3 51 | ticker_t ta, tb; 52 | 53 | ticker_init(&ta, NTICKS); 54 | ticker_copy(&tb, &ta); 55 | assert_u_eq(ticker_read(&tb), NTICKS, "Unexpected ticker value"); 56 | assert_true(ticker_ticks(&tb, NTICKS + 1), "Expected ticker fire"); 57 | assert_u_eq(ticker_read(&tb), NTICKS, "Unexpected ticker value"); 58 | 59 | ticker_tick(&ta); 60 | ticker_copy(&tb, &ta); 61 | assert_u_eq(ticker_read(&tb), NTICKS - 1, "Unexpected ticker value"); 62 | assert_true(ticker_ticks(&tb, NTICKS), "Expected ticker fire"); 63 | assert_u_eq(ticker_read(&tb), NTICKS, "Unexpected ticker value"); 64 | #undef NTICKS 65 | } 66 | TEST_END 67 | 68 | int 69 | main(void) 70 | { 71 | 72 | return (test( 73 | test_ticker_tick, 74 | test_ticker_ticks, 75 | test_ticker_copy)); 76 | } 77 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/unit/tsd.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | #define THREAD_DATA 0x72b65c10 4 | 5 | typedef unsigned int data_t; 6 | 7 | static bool data_cleanup_executed; 8 | 9 | malloc_tsd_types(data_, data_t) 10 | malloc_tsd_protos(, data_, data_t) 11 | 12 | void 13 | data_cleanup(void *arg) 14 | { 15 | data_t *data = (data_t *)arg; 16 | 17 | if (!data_cleanup_executed) { 18 | assert_x_eq(*data, THREAD_DATA, 19 | "Argument passed into cleanup function should match tsd " 20 | "value"); 21 | } 22 | data_cleanup_executed = true; 23 | 24 | /* 25 | * Allocate during cleanup for two rounds, in order to assure that 26 | * jemalloc's internal tsd reinitialization happens. 27 | */ 28 | switch (*data) { 29 | case THREAD_DATA: 30 | *data = 1; 31 | data_tsd_set(data); 32 | break; 33 | case 1: 34 | *data = 2; 35 | data_tsd_set(data); 36 | break; 37 | case 2: 38 | return; 39 | default: 40 | not_reached(); 41 | } 42 | 43 | { 44 | void *p = mallocx(1, 0); 45 | assert_ptr_not_null(p, "Unexpeced mallocx() failure"); 46 | dallocx(p, 0); 47 | } 48 | } 49 | 50 | malloc_tsd_externs(data_, data_t) 51 | #define DATA_INIT 0x12345678 52 | malloc_tsd_data(, data_, data_t, DATA_INIT) 53 | malloc_tsd_funcs(, data_, data_t, DATA_INIT, data_cleanup) 54 | 55 | static void * 56 | thd_start(void *arg) 57 | { 58 | data_t d = (data_t)(uintptr_t)arg; 59 | void *p; 60 | 61 | assert_x_eq(*data_tsd_get(true), DATA_INIT, 62 | "Initial tsd get should return initialization value"); 63 | 64 | p = malloc(1); 65 | assert_ptr_not_null(p, "Unexpected malloc() failure"); 66 | 67 | data_tsd_set(&d); 68 | assert_x_eq(*data_tsd_get(true), d, 69 | "After tsd set, tsd get should return value that was set"); 70 | 71 | d = 0; 72 | assert_x_eq(*data_tsd_get(true), (data_t)(uintptr_t)arg, 73 | "Resetting local data should have no effect on tsd"); 74 | 75 | free(p); 76 | return (NULL); 77 | } 78 | 79 | TEST_BEGIN(test_tsd_main_thread) 80 | { 81 | 82 | thd_start((void *)(uintptr_t)0xa5f3e329); 83 | } 84 | TEST_END 85 | 86 | TEST_BEGIN(test_tsd_sub_thread) 87 | { 88 | thd_t thd; 89 | 90 | data_cleanup_executed = false; 91 | thd_create(&thd, thd_start, (void *)THREAD_DATA); 92 | thd_join(thd, NULL); 93 | assert_true(data_cleanup_executed, 94 | "Cleanup function should have executed"); 95 | } 96 | TEST_END 97 | 98 | int 99 | main(void) 100 | { 101 | 102 | /* Core tsd bootstrapping must happen prior to data_tsd_boot(). */ 103 | if (nallocx(1, 0) == 0) { 104 | malloc_printf("Initialization error"); 105 | return (test_status_fail); 106 | } 107 | data_tsd_boot(); 108 | 109 | return (test( 110 | test_tsd_main_thread, 111 | test_tsd_sub_thread)); 112 | } 113 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/unit/zero.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | static void 4 | test_zero(size_t sz_min, size_t sz_max) 5 | { 6 | uint8_t *s; 7 | size_t sz_prev, sz, i; 8 | #define MAGIC ((uint8_t)0x61) 9 | 10 | sz_prev = 0; 11 | s = (uint8_t *)mallocx(sz_min, 0); 12 | assert_ptr_not_null((void *)s, "Unexpected mallocx() failure"); 13 | 14 | for (sz = sallocx(s, 0); sz <= sz_max; 15 | sz_prev = sz, sz = sallocx(s, 0)) { 16 | if (sz_prev > 0) { 17 | assert_u_eq(s[0], MAGIC, 18 | "Previously allocated byte %zu/%zu is corrupted", 19 | ZU(0), sz_prev); 20 | assert_u_eq(s[sz_prev-1], MAGIC, 21 | "Previously allocated byte %zu/%zu is corrupted", 22 | sz_prev-1, sz_prev); 23 | } 24 | 25 | for (i = sz_prev; i < sz; i++) { 26 | assert_u_eq(s[i], 0x0, 27 | "Newly allocated byte %zu/%zu isn't zero-filled", 28 | i, sz); 29 | s[i] = MAGIC; 30 | } 31 | 32 | if (xallocx(s, sz+1, 0, 0) == sz) { 33 | s = (uint8_t *)rallocx(s, sz+1, 0); 34 | assert_ptr_not_null((void *)s, 35 | "Unexpected rallocx() failure"); 36 | } 37 | } 38 | 39 | dallocx(s, 0); 40 | #undef MAGIC 41 | } 42 | 43 | TEST_BEGIN(test_zero_small) 44 | { 45 | 46 | test_skip_if(!config_fill); 47 | test_zero(1, SMALL_MAXCLASS-1); 48 | } 49 | TEST_END 50 | 51 | TEST_BEGIN(test_zero_large) 52 | { 53 | 54 | test_skip_if(!config_fill); 55 | test_zero(SMALL_MAXCLASS+1, large_maxclass); 56 | } 57 | TEST_END 58 | 59 | TEST_BEGIN(test_zero_huge) 60 | { 61 | 62 | test_skip_if(!config_fill); 63 | test_zero(large_maxclass+1, chunksize*2); 64 | } 65 | TEST_END 66 | 67 | int 68 | main(void) 69 | { 70 | 71 | return (test( 72 | test_zero_small, 73 | test_zero_large, 74 | test_zero_huge)); 75 | } 76 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc-4.5.0/test/unit/zero.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "x${enable_fill}" = "x1" ] ; then 4 | export MALLOC_CONF="abort:false,junk:false,zero:true,redzone:false,quarantine:0" 5 | fi 6 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc.go: -------------------------------------------------------------------------------- 1 | package jemalloc 2 | 3 | // #cgo CFLAGS: -I. -std=gnu99 4 | // #cgo CPPFLAGS: -D_REENTRANT 5 | // #cgo linux CPPFLAGS: -D_GNU_SOURCE 6 | // #cgo LDFLAGS: -lm 7 | // #cgo linux LDFLAGS: -lrt 8 | // #include 9 | import "C" 10 | 11 | import "unsafe" 12 | 13 | func Calloc(count, size int) unsafe.Pointer { 14 | return C.je_calloc(C.size_t(count), C.size_t(size)) 15 | } 16 | 17 | func Malloc(size int) unsafe.Pointer { 18 | return C.je_malloc(C.size_t(size)) 19 | } 20 | 21 | func Valloc(size int) unsafe.Pointer { 22 | return C.je_valloc(C.size_t(size)) 23 | } 24 | 25 | func Realloc(ptr unsafe.Pointer, size int) unsafe.Pointer { 26 | return C.je_realloc(ptr, C.size_t(size)) 27 | } 28 | 29 | func Free(ptr unsafe.Pointer) { 30 | C.je_free(ptr) 31 | } 32 | -------------------------------------------------------------------------------- /vendor/github.com/spinlock/jemalloc-go/jemalloc_test.go: -------------------------------------------------------------------------------- 1 | package jemalloc_test 2 | 3 | import ( 4 | "reflect" 5 | "testing" 6 | "unsafe" 7 | 8 | jemalloc "github.com/spinlock/jemalloc-go" 9 | ) 10 | 11 | func toBytes(ptr unsafe.Pointer, size int) []byte { 12 | p := &reflect.SliceHeader{} 13 | p.Data = uintptr(ptr) 14 | p.Len = size 15 | p.Cap = size 16 | return *(*[]byte)(unsafe.Pointer(p)) 17 | } 18 | 19 | func TestMalloc(t *testing.T) { 20 | p1 := jemalloc.Malloc(100) 21 | if p1 == nil { 22 | t.Fatalf("malloc failed") 23 | } 24 | b1 := toBytes(p1, 100) 25 | for i := 0; i < 100; i++ { 26 | b1[i] = byte(i) 27 | } 28 | 29 | p2 := jemalloc.Realloc(p1, 200) 30 | if p2 == nil { 31 | t.Fatalf("realloc failed") 32 | } 33 | b2 := toBytes(p2, 200) 34 | for i := 0; i < 100; i++ { 35 | if b2[i] != byte(i) { 36 | t.Fatalf("realloc failed") 37 | } 38 | } 39 | jemalloc.Free(p2) 40 | } 41 | -------------------------------------------------------------------------------- /version: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | version=`git log --date=iso --pretty=format:"%cd @%H" -1` 4 | if [ $? -ne 0 ]; then 5 | version="unknown version" 6 | fi 7 | 8 | compile=`date +"%F %T %z"`" by "`go version` 9 | if [ $? -ne 0 ]; then 10 | compile="unknown datetime" 11 | fi 12 | 13 | describe=`git describe --tags 2>/dev/null` 14 | if [ $? -eq 0 ]; then 15 | version="${version} @${describe}" 16 | fi 17 | 18 | cat << EOF | gofmt > cmd/version.go 19 | package main 20 | 21 | const ( 22 | Version = "$version" 23 | Compile = "$compile" 24 | ) 25 | EOF 26 | 27 | cat << EOF > bin/version 28 | version = $version 29 | compile = $compile 30 | EOF 31 | -------------------------------------------------------------------------------- /wandoujia_license.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Wandoujia Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | --------------------------------------------------------------------------------