// File: /workspace/github_c_makefile_star2_O1/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 0x298c5(%rip), %eax     # 0x4c5d4
testq %rax, %rax
je 0x22d33
movq 0xd0(%rbx), %rcx
shlq $0x5, %rax
xorl %edx, %edx
movq $0x0, 0x18(%rcx,%rdx)
addq $0x20, %rdx
cmpq %rdx, %rax
jne 0x22d21
leaq 0x830(%rbx), %r15
movq %r15, %rdi
callq 0xb5a0
movq 0x828(%rbx), %rax
testq %rax, %rax
je 0x22d54
movq 0x58(%rax), %rax
jmp 0x22d56
xorl %eax, %eax
testq %rax, %rax
je 0x22e57
movl $0xff, %ebp
movq 0x8(%rax), %r12
movq %r15, %rdi
callq 0xb380
leaq 0x2a359(%rip), %rax     # 0x4d0d0
movq (%rax), %rax
notq %rax
andq %r12, %rax
movq %r12, %rcx
subq %rax, %rcx
je 0x22e27
shrq $0xc, %rcx
subq 0x2a229(%rip), %rcx     # 0x4cfc0
movq 0x78(%rax,%rcx,8), %r13
movl %r13d, %eax
shrl $0x5, %eax
andl %ebp, %eax
cmpl %ebp, %eax
je 0x22e41
movl %eax, %eax
leaq 0x1888b(%rip), %rcx     # 0x3b640
movq (%rcx,%rax,8), %r13
movq %r14, %rdi
movq %r12, %rsi
callq 0x11227
movq %r15, %rdi
callq 0xb5a0
cmpq $0x1000, %r13           # imm = 0x1000
ja 0x22e37
decq %r13
shrq $0x3, %r13
leaq 0x18fdd(%rip), %rax     # 0x3bdc0
movzbl (%rax,%r13), %eax
subl 0x297e6(%rip), %eax     # 0x4c5d4
addl $-0x27, %eax
incq 0xc8(%rbx)
movq 0xd8(%rbx), %rcx
leaq (%rax,%rax,2), %rax
decq 0x8(%rcx,%rax,8)
movq 0x828(%rbx), %rax
testq %rax, %rax
je 0x22e1a
movq 0x58(%rax), %rax
jmp 0x22e1c
xorl %eax, %eax
testq %rax, %rax
jne 0x22d64
jmp 0x22e57
movq %r14, %rdi
movq %r12, %rsi
callq 0x2e4e2
movq %rax, %r13
jmp 0x22db9
movq %r13, %rdi
callq 0xfdc2
jmp 0x22de8
shrq %r13
andq $-0x1000, %r13          # imm = 0xF000
addq $-0x1000, %r13          # imm = 0xF000
jmp 0x22db9
movq %r15, %rdi
callq 0xb380
leaq 0x10(%rbx), %rdi
movq %rdi, (%rsp)
callq 0xb5a0
leaq 0x980(%rbx), %r13
xorl %ebp, %ebp
xorl %r15d, %r15d
leaq (%r15,%r13), %r12
movq %r12, %rdi
callq 0xb5a0
movq %rbp, 0x9f8(%rbx,%r15)
movq %rbp, 0xa20(%rbx,%r15)
xorps %xmm0, %xmm0
movups %xmm0, 0x9d0(%rbx,%r15)
movq %r12, %rdi
callq 0xb380
addq $0xa8, %r15
cmpq $0x1998, %r15           # imm = 0x1998
jne 0x22e78
leaq 0x138(%rbx), %rax
movq %rax, 0x138(%rbx)
movq %rax, 0x140(%rbx)
leaq 0x148(%rbx), %rcx
movq 0x188(%rbx), %rdx
cmpq %rcx, %rdx
je 0x22f73
movq 0x140(%rbx), %rsi
movq %rsi, %rdi
leaq 0x30(%rdx), %rsi
movq %rsi, 0x30(%rdx)
movq %rsi, 0x38(%rdx)
movq %rsi, (%rdi)
movq %rax, 0x30(%rdx)
movq %rdi, 0x38(%rdx)
movq 0x40(%rdx), %rdx
cmpq %rcx, %rdx
jne 0x22eeb
movq %rsi, 0x140(%rbx)
jmp 0x22f73
movq 0x100(%rbx), %rcx
cmpq %rax, %rcx
jne 0x22f2e
movq 0x50(%rcx), %rcx
movq %rcx, 0x100(%rbx)
cmpq %rax, 0x100(%rbx)
je 0x22f59
movq 0x50(%rax), %rcx
movq 0x58(%rax), %rdx
movq %rcx, 0x50(%rdx)
movq 0x50(%rax), %rcx
movq 0x58(%rax), %rdx
movq %rdx, 0x58(%rcx)
movq %rax, 0x50(%rax)
movq %rax, 0x58(%rax)
jmp 0x22f64
movq $0x0, 0x100(%rbx)
movq 0x8(%rax), %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x22fe6
movq 0x100(%rbx), %rax
testq %rax, %rax
je 0x22f85
movq 0x58(%rax), %rax
jmp 0x22f87
xorl %eax, %eax
testq %rax, %rax
jne 0x22f17
movq 0x110(%rbx), %rdx
testq %rdx, %rdx
je 0x22fae
movq %r14, %rdi
movq %rbx, %rsi
callq 0x22fe6
movq $0x0, 0x110(%rbx)
movq $0x0, 0x128(%rbx)
addq $0x2318, %rbx           # imm = 0x2318
movl $0x638, %edx            # imm = 0x638
movq %rbx, %rdi
xorl %esi, %esi
callq 0xb230
movq (%rsp), %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xb380