// File: /workspace/github_c_makefile_star2_O2/zhou-yuxin[P]redis-aof-no-cow/deps/jemalloc/src/arena.c
// Function: je_arena_reset
void
arena_reset(tsd_t *tsd, arena_t *arena)
{
	unsigned i;
	extent_node_t *node;

	/*
	 * Locking in this function is unintuitive.  The caller guarantees that
	 * no concurrent operations are happening in this arena, but there are
	 * still reasons that some locking is necessary:
	 *
	 * - Some of the functions in the transitive closure of calls assume
	 *   appropriate locks are held, and in some cases these locks are
	 *   temporarily dropped to avoid lock order reversal or deadlock due to
	 *   reentry.
	 * - mallctl("epoch", ...) may concurrently refresh stats.  While
	 *   strictly speaking this is a "concurrent operation", disallowing
	 *   stats refreshes would impose an inconvenient burden.
	 */

	/* Remove large allocations from prof sample set. */
	if (config_prof && opt_prof) {
		ql_foreach(node, &arena->achunks, ql_link) {
			arena_achunk_prof_reset(tsd, arena,
			    extent_node_addr_get(node));
		}
	}

	/* Reset curruns for large size classes. */
	if (config_stats) {
		for (i = 0; i < nlclasses; i++)
			arena->stats.lstats[i].curruns = 0;
	}

	/* Huge allocations. */
	malloc_mutex_lock(tsd_tsdn(tsd), &arena->huge_mtx);
	for (node = ql_last(&arena->huge, ql_link); node != NULL; node =
	    ql_last(&arena->huge, ql_link)) {
		void *ptr = extent_node_addr_get(node);
		size_t usize;

		malloc_mutex_unlock(tsd_tsdn(tsd), &arena->huge_mtx);
		if (config_stats || (config_prof && opt_prof))
			usize = isalloc(tsd_tsdn(tsd), ptr, config_prof);
		/* Remove huge allocation from prof sample set. */
		if (config_prof && opt_prof)
			prof_free(tsd, ptr, usize);
		huge_dalloc(tsd_tsdn(tsd), ptr);
		malloc_mutex_lock(tsd_tsdn(tsd), &arena->huge_mtx);
		/* Cancel out unwanted effects on stats. */
		if (config_stats)
			arena_huge_reset_stats_cancel(arena, usize);
	}
	malloc_mutex_unlock(tsd_tsdn(tsd), &arena->huge_mtx);

	malloc_mutex_lock(tsd_tsdn(tsd), &arena->lock);

	/* Bins. */
	for (i = 0; i < NBINS; i++) {
		arena_bin_t *bin = &arena->bins[i];
		malloc_mutex_lock(tsd_tsdn(tsd), &bin->lock);
		bin->runcur = NULL;
		arena_run_heap_new(&bin->runs);
		if (config_stats) {
			bin->stats.curregs = 0;
			bin->stats.curruns = 0;
		}
		malloc_mutex_unlock(tsd_tsdn(tsd), &bin->lock);
	}

	/*
	 * Re-initialize runs_dirty such that the chunks_cache and runs_dirty
	 * chains directly correspond.
	 */
	qr_new(&arena->runs_dirty, rd_link);
	for (node = qr_next(&arena->chunks_cache, cc_link);
	    node != &arena->chunks_cache; node = qr_next(node, cc_link)) {
		qr_new(&node->rd, rd_link);
		qr_meld(&arena->runs_dirty, &node->rd, rd_link);
	}

	/* Arena chunks. */
	for (node = ql_last(&arena->achunks, ql_link); node != NULL; node =
	    ql_last(&arena->achunks, ql_link)) {
		ql_remove(&arena->achunks, node, ql_link);
		arena_chunk_discard(tsd_tsdn(tsd), arena,
		    extent_node_addr_get(node));
	}

	/* Spare. */
	if (arena->spare != NULL) {
		arena_chunk_discard(tsd_tsdn(tsd), arena, arena->spare);
		arena->spare = NULL;
	}

	assert(!arena->purging);
	arena->nactive = 0;

	for (i = 0; i < NPSIZES; i++)
		arena_run_heap_new(&arena->runs_avail[i]);

	malloc_mutex_unlock(tsd_tsdn(tsd), &arena->lock);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
movl 0x2d557(%rip), %eax     # 0x485d4
shlq $0x5, %rax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x1b09b
movq 0xd0(%rbx), %rdx
andq $0x0, 0x18(%rdx,%rcx)
addq $0x20, %rcx
jmp 0x1b083
leaq 0x830(%rbx), %r15
movq %r15, %rdi
callq 0xb5a0
movq 0x828(%rbx), %rax
testq %rax, %rax
je 0x1b0bc
movq 0x58(%rax), %rax
jmp 0x1b0be
xorl %eax, %eax
movl $0xff, %ebp
testq %rax, %rax
je 0x1b1be
movq 0x8(%rax), %r12
movq %r15, %rdi
callq 0xb380
leaq 0x2dff1(%rip), %rax     # 0x490d0
movq (%rax), %rax
notq %rax
andq %r12, %rax
movq %r12, %rcx
subq %rax, %rcx
je 0x1b18e
shrq $0xc, %rcx
subq 0x2dec1(%rip), %rcx     # 0x48fc0
movq 0x78(%rax,%rcx,8), %r13
movl %r13d, %eax
shrl $0x5, %eax
andl %ebp, %eax
cmpl %ebp, %eax
je 0x1b1a8
movl %eax, %eax
leaq 0x1b123(%rip), %rcx     # 0x36240
movq (%rcx,%rax,8), %r13
movq %r14, %rdi
movq %r12, %rsi
callq 0x28fb2
movq %r15, %rdi
callq 0xb5a0
cmpq $0x1000, %r13           # imm = 0x1000
ja 0x1b19e
decq %r13
shrq $0x3, %r13
leaq 0x1b875(%rip), %rax     # 0x369c0
movzbl (%rax,%r13), %eax
subl 0x2d47e(%rip), %eax     # 0x485d4
addl $-0x27, %eax
incq 0xc8(%rbx)
movq 0xd8(%rbx), %rcx
imulq $0x18, %rax, %rax
decq 0x8(%rcx,%rax)
movq 0x828(%rbx), %rcx
movl $0x0, %eax
testq %rcx, %rcx
je 0x1b0c3
movq 0x58(%rcx), %rax
jmp 0x1b0c3
movq %r14, %rdi
movq %r12, %rsi
callq 0x292e1
movq %rax, %r13
jmp 0x1b121
movq %r13, %rdi
callq 0x20acc
jmp 0x1b150
shrq %r13
andq $-0x1000, %r13          # imm = 0xF000
addq $-0x1000, %r13          # imm = 0xF000
jmp 0x1b121
movq %r15, %rdi
callq 0xb380
leaq 0x10(%rbx), %r15
movq %r15, %rdi
callq 0xb5a0
leaq 0x980(%rbx), %r13
xorl %ebp, %ebp
cmpq $0x1998, %rbp           # imm = 0x1998
je 0x1b220
movq %r13, %r12
addq %rbp, %r12
movq %r12, %rdi
callq 0xb5a0
andq $0x0, 0x9f8(%rbx,%rbp)
andq $0x0, 0xa20(%rbx,%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0x9d0(%rbx,%rbp)
movq %r12, %rdi
callq 0xb380
addq $0xa8, %rbp
jmp 0x1b1db
leaq 0x138(%rbx), %rax
movq %rax, 0x138(%rbx)
movq %rax, 0x140(%rbx)
leaq 0x148(%rbx), %rcx
leaq 0x188(%rbx), %rdx
movq %rax, %rsi
movq (%rdx), %rdx
cmpq %rcx, %rdx
je 0x1b26d
leaq 0x30(%rdx), %rdi
movq %rdi, (%rsi)
movq %rax, 0x30(%rdx)
movq %rdi, 0x140(%rbx)
movq %rsi, 0x38(%rdx)
addq $0x40, %rdx
movq %rdi, %rsi
jmp 0x1b246
movq 0x100(%rbx), %rcx
testq %rcx, %rcx
jne 0x1b27d
xorl %eax, %eax
jmp 0x1b281
movq 0x58(%rcx), %rax
testq %rax, %rax
je 0x1b2e3
cmpq %rax, %rcx
jne 0x1b296
movq 0x50(%rcx), %rcx
movq %rcx, 0x100(%rbx)
cmpq %rax, %rcx
je 0x1b2b9
movq 0x50(%rax), %rcx
movq 0x58(%rax), %rdx
movq %rcx, 0x50(%rdx)
movq 0x58(%rax), %rdx
movq %rdx, 0x58(%rcx)
movq %rax, 0x50(%rax)
movq %rax, 0x58(%rax)
jmp 0x1b2c1
andq $0x0, 0x100(%rbx)
movq 0x8(%rax), %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1b338
movq 0x100(%rbx), %rcx
movl $0x0, %eax
testq %rcx, %rcx
je 0x1b281
jmp 0x1b27d
movq 0x110(%rbx), %rdx
testq %rdx, %rdx
je 0x1b302
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1b338
andq $0x0, 0x110(%rbx)
andq $0x0, 0x128(%rbx)
xorl %eax, %eax
cmpq $0xc7, %rax
je 0x1b322
andq $0x0, 0x2318(%rbx,%rax,8)
incq %rax
jmp 0x1b30c
movq %r15, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xb380