Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | #define JEMALLOC_MANGLE |
michael@0 | 2 | #include "jemalloc_test.h" |
michael@0 | 3 | |
michael@0 | 4 | #define NTHREADS 10 |
michael@0 | 5 | |
michael@0 | 6 | void * |
michael@0 | 7 | je_thread_start(void *arg) |
michael@0 | 8 | { |
michael@0 | 9 | unsigned thread_ind = (unsigned)(uintptr_t)arg; |
michael@0 | 10 | unsigned arena_ind; |
michael@0 | 11 | int r; |
michael@0 | 12 | void *p; |
michael@0 | 13 | size_t rsz, sz; |
michael@0 | 14 | |
michael@0 | 15 | sz = sizeof(arena_ind); |
michael@0 | 16 | if (mallctl("arenas.extend", &arena_ind, &sz, NULL, 0) |
michael@0 | 17 | != 0) { |
michael@0 | 18 | malloc_printf("Error in arenas.extend\n"); |
michael@0 | 19 | abort(); |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | if (thread_ind % 4 != 3) { |
michael@0 | 23 | size_t mib[3]; |
michael@0 | 24 | size_t miblen = sizeof(mib) / sizeof(size_t); |
michael@0 | 25 | const char *dss_precs[] = {"disabled", "primary", "secondary"}; |
michael@0 | 26 | const char *dss = dss_precs[thread_ind % 4]; |
michael@0 | 27 | if (mallctlnametomib("arena.0.dss", mib, &miblen) != 0) { |
michael@0 | 28 | malloc_printf("Error in mallctlnametomib()\n"); |
michael@0 | 29 | abort(); |
michael@0 | 30 | } |
michael@0 | 31 | mib[1] = arena_ind; |
michael@0 | 32 | if (mallctlbymib(mib, miblen, NULL, NULL, (void *)&dss, |
michael@0 | 33 | sizeof(const char *))) { |
michael@0 | 34 | malloc_printf("Error in mallctlbymib()\n"); |
michael@0 | 35 | abort(); |
michael@0 | 36 | } |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | r = allocm(&p, &rsz, 1, ALLOCM_ARENA(arena_ind)); |
michael@0 | 40 | if (r != ALLOCM_SUCCESS) { |
michael@0 | 41 | malloc_printf("Unexpected allocm() error\n"); |
michael@0 | 42 | abort(); |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | return (NULL); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | int |
michael@0 | 49 | main(void) |
michael@0 | 50 | { |
michael@0 | 51 | je_thread_t threads[NTHREADS]; |
michael@0 | 52 | unsigned i; |
michael@0 | 53 | |
michael@0 | 54 | malloc_printf("Test begin\n"); |
michael@0 | 55 | |
michael@0 | 56 | for (i = 0; i < NTHREADS; i++) { |
michael@0 | 57 | je_thread_create(&threads[i], je_thread_start, |
michael@0 | 58 | (void *)(uintptr_t)i); |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | for (i = 0; i < NTHREADS; i++) |
michael@0 | 62 | je_thread_join(threads[i], NULL); |
michael@0 | 63 | |
michael@0 | 64 | malloc_printf("Test end\n"); |
michael@0 | 65 | return (0); |
michael@0 | 66 | } |