mi_assert(page != NULL);
if (page == NULL) return true;
- _mi_page_free_collect(page,true);
mi_assert_internal(page->local_free == NULL);
if (page->used == 0) return true;
typedef bool (mi_heap_area_visit_fun)(const mi_heap_t* heap, const mi_heap_area_ex_t* area, void* arg);
void _mi_heap_area_init(mi_heap_area_t* area, mi_page_t* page) {
+ _mi_page_free_collect(page,true);
const size_t bsize = mi_page_block_size(page);
const size_t ubsize = mi_page_usable_block_size(page);
area->reserved = page->reserved * bsize;
if (should_queue) {
// TODO: the inter-thread queue is not yet implemented. For now,
// we just merge the refcount here.
+#ifdef Py_REF_DEBUG
+ _Py_IncRefTotal(_PyInterpreterState_GET());
+#endif
Py_ssize_t refcount = _Py_ExplicitMergeRefcount(o, -1);
if (refcount == 0) {
_Py_Dealloc(o);
Py_ssize_t shared = _Py_atomic_load_ssize_relaxed(&op->ob_ref_shared);
do {
refcnt = Py_ARITHMETIC_RIGHT_SHIFT(Py_ssize_t, shared, _Py_REF_SHARED_SHIFT);
- if (_Py_REF_IS_MERGED(shared)) {
- return refcnt;
- }
-
refcnt += (Py_ssize_t)op->ob_ref_local;
refcnt += extra;
} while (!_Py_atomic_compare_exchange_ssize(&op->ob_ref_shared,
&shared, new_shared));
+#ifdef Py_REF_DEBUG
+ _Py_AddRefTotal(_PyInterpreterState_GET(), extra);
+#endif
+
_Py_atomic_store_uint32_relaxed(&op->ob_ref_local, 0);
_Py_atomic_store_uintptr_relaxed(&op->ob_tid, 0);
return refcnt;
mi_heap_visit_blocks(heap, false, &count_blocks, &allocated_blocks);
}
}
- // TODO(sgross): count blocks in abandoned segments.
+
+ mi_abandoned_pool_t *pool = &interp->mimalloc.abandoned_pool;
+ for (uint8_t tag = 0; tag < _Py_MIMALLOC_HEAP_COUNT; tag++) {
+ _mi_abandoned_pool_visit_blocks(pool, tag, false, &count_blocks,
+ &allocated_blocks);
+ }
#else
// TODO(sgross): this only counts the current thread's blocks.
mi_heap_t *heap = mi_heap_get_default();
}
}
else {
+ _PyEval_StopTheWorldAll(&_PyRuntime);
HEAD_LOCK(runtime);
PyInterpreterState *interp = PyInterpreterState_Head();
assert(interp != NULL);
}
}
HEAD_UNLOCK(runtime);
+ _PyEval_StartTheWorldAll(&_PyRuntime);
#ifdef Py_DEBUG
assert(got_main);
#endif