diff options
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/bytesobject.c | 16 | ||||
-rw-r--r-- | Objects/listobject.c | 36 | ||||
-rw-r--r-- | Objects/longobject.c | 10 | ||||
-rw-r--r-- | Objects/object.c | 126 | ||||
-rw-r--r-- | Objects/tupleobject.c | 46 |
5 files changed, 0 insertions, 234 deletions
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index 5fd92f7..00151b8 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -18,10 +18,6 @@ class bytes "PyBytesObject *" "&PyBytes_Type" #include "clinic/bytesobject.c.h" -#ifdef COUNT_ALLOCS -Py_ssize_t _Py_null_strings, _Py_one_strings; -#endif - static PyBytesObject *characters[UCHAR_MAX + 1]; static PyBytesObject *nullstring; @@ -68,9 +64,6 @@ _PyBytes_FromSize(Py_ssize_t size, int use_calloc) assert(size >= 0); if (size == 0 && (op = nullstring) != NULL) { -#ifdef COUNT_ALLOCS - _Py_null_strings++; -#endif Py_INCREF(op); return (PyObject *)op; } @@ -112,9 +105,6 @@ PyBytes_FromStringAndSize(const char *str, Py_ssize_t size) if (size == 1 && str != NULL && (op = characters[*str & UCHAR_MAX]) != NULL) { -#ifdef COUNT_ALLOCS - _Py_one_strings++; -#endif Py_INCREF(op); return (PyObject *)op; } @@ -148,16 +138,10 @@ PyBytes_FromString(const char *str) return NULL; } if (size == 0 && (op = nullstring) != NULL) { -#ifdef COUNT_ALLOCS - _Py_null_strings++; -#endif Py_INCREF(op); return (PyObject *)op; } if (size == 1 && (op = characters[*str & UCHAR_MAX]) != NULL) { -#ifdef COUNT_ALLOCS - _Py_one_strings++; -#endif Py_INCREF(op); return (PyObject *)op; } diff --git a/Objects/listobject.c b/Objects/listobject.c index 2c07ceb..c93a0fe 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -94,29 +94,6 @@ list_preallocate_exact(PyListObject *self, Py_ssize_t size) return 0; } -/* Debug statistic to compare allocations with reuse through the free list */ -#undef SHOW_ALLOC_COUNT -#ifdef SHOW_ALLOC_COUNT -static size_t count_alloc = 0; -static size_t count_reuse = 0; - -static void -show_alloc(void) -{ - PyInterpreterState *interp = _PyInterpreterState_Get(); - if (!interp->config.show_alloc_count) { - return; - } - - fprintf(stderr, "List allocations: %" PY_FORMAT_SIZE_T "d\n", - count_alloc); - fprintf(stderr, "List reuse through freelist: %" PY_FORMAT_SIZE_T - "d\n", count_reuse); - fprintf(stderr, "%.2f%% reuse rate\n\n", - (100.0*count_reuse/(count_alloc+count_reuse))); -} -#endif - /* Empty list reuse scheme to save calls to malloc and free */ #ifndef PyList_MAXFREELIST #define PyList_MAXFREELIST 80 @@ -156,13 +133,6 @@ PyObject * PyList_New(Py_ssize_t size) { PyListObject *op; -#ifdef SHOW_ALLOC_COUNT - static int initialized = 0; - if (!initialized) { - Py_AtExit(show_alloc); - initialized = 1; - } -#endif if (size < 0) { PyErr_BadInternalCall(); @@ -172,16 +142,10 @@ PyList_New(Py_ssize_t size) numfree--; op = free_list[numfree]; _Py_NewReference((PyObject *)op); -#ifdef SHOW_ALLOC_COUNT - count_reuse++; -#endif } else { op = PyObject_GC_New(PyListObject, &PyList_Type); if (op == NULL) return NULL; -#ifdef SHOW_ALLOC_COUNT - count_alloc++; -#endif } if (size <= 0) op->ob_item = NULL; diff --git a/Objects/longobject.c b/Objects/longobject.c index 124b837..9115fa1 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -35,10 +35,6 @@ PyObject *_PyLong_One = NULL; #define IS_SMALL_INT(ival) (-NSMALLNEGINTS <= (ival) && (ival) < NSMALLPOSINTS) #define IS_SMALL_UINT(ival) ((ival) < NSMALLPOSINTS) -#ifdef COUNT_ALLOCS -Py_ssize_t _Py_quick_int_allocs, _Py_quick_neg_int_allocs; -#endif - static PyObject * get_small_int(sdigit ival) { @@ -46,12 +42,6 @@ get_small_int(sdigit ival) PyThreadState *tstate = _PyThreadState_GET(); PyObject *v = (PyObject*)tstate->interp->small_ints[ival + NSMALLNEGINTS]; Py_INCREF(v); -#ifdef COUNT_ALLOCS - if (ival >= 0) - _Py_quick_int_allocs++; - else - _Py_quick_neg_int_allocs++; -#endif return v; } diff --git a/Objects/object.c b/Objects/object.c index 67a6386..2154d11 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -113,120 +113,6 @@ _Py_AddToAllObjects(PyObject *op, int force) } #endif /* Py_TRACE_REFS */ -#ifdef COUNT_ALLOCS -static PyTypeObject *type_list; -/* All types are added to type_list, at least when - they get one object created. That makes them - immortal, which unfortunately contributes to - garbage itself. If unlist_types_without_objects - is set, they will be removed from the type_list - once the last object is deallocated. */ -static int unlist_types_without_objects; -extern Py_ssize_t _Py_tuple_zero_allocs, _Py_fast_tuple_allocs; -extern Py_ssize_t _Py_quick_int_allocs, _Py_quick_neg_int_allocs; -extern Py_ssize_t _Py_null_strings, _Py_one_strings; -void -_Py_dump_counts(FILE* f) -{ - PyInterpreterState *interp = _PyInterpreterState_Get(); - if (!interp->config.show_alloc_count) { - return; - } - - PyTypeObject *tp; - for (tp = type_list; tp; tp = tp->tp_next) - fprintf(f, "%s alloc'd: %" PY_FORMAT_SIZE_T "d, " - "freed: %" PY_FORMAT_SIZE_T "d, " - "max in use: %" PY_FORMAT_SIZE_T "d\n", - tp->tp_name, tp->tp_allocs, tp->tp_frees, - tp->tp_maxalloc); - fprintf(f, "fast tuple allocs: %" PY_FORMAT_SIZE_T "d, " - "empty: %" PY_FORMAT_SIZE_T "d\n", - _Py_fast_tuple_allocs, _Py_tuple_zero_allocs); - fprintf(f, "fast int allocs: pos: %" PY_FORMAT_SIZE_T "d, " - "neg: %" PY_FORMAT_SIZE_T "d\n", - _Py_quick_int_allocs, _Py_quick_neg_int_allocs); - fprintf(f, "null strings: %" PY_FORMAT_SIZE_T "d, " - "1-strings: %" PY_FORMAT_SIZE_T "d\n", - _Py_null_strings, _Py_one_strings); -} - -PyObject * -_Py_get_counts(void) -{ - PyTypeObject *tp; - PyObject *result; - PyObject *v; - - result = PyList_New(0); - if (result == NULL) - return NULL; - for (tp = type_list; tp; tp = tp->tp_next) { - v = Py_BuildValue("(snnn)", tp->tp_name, tp->tp_allocs, - tp->tp_frees, tp->tp_maxalloc); - if (v == NULL) { - Py_DECREF(result); - return NULL; - } - if (PyList_Append(result, v) < 0) { - Py_DECREF(v); - Py_DECREF(result); - return NULL; - } - Py_DECREF(v); - } - return result; -} - -void -_Py_inc_count(PyTypeObject *tp) -{ - if (tp->tp_next == NULL && tp->tp_prev == NULL) { - /* first time; insert in linked list */ - if (type_list) - type_list->tp_prev = tp; - tp->tp_next = type_list; - /* Note that as of Python 2.2, heap-allocated type objects - * can go away, but this code requires that they stay alive - * until program exit. That's why we're careful with - * refcounts here. type_list gets a new reference to tp, - * while ownership of the reference type_list used to hold - * (if any) was transferred to tp->tp_next in the line above. - * tp is thus effectively immortal after this. - */ - Py_INCREF(tp); - type_list = tp; -#ifdef Py_TRACE_REFS - /* Also insert in the doubly-linked list of all objects, - * if not already there. - */ - _Py_AddToAllObjects((PyObject *)tp, 0); -#endif - } - tp->tp_allocs++; - if (tp->tp_allocs - tp->tp_frees > tp->tp_maxalloc) - tp->tp_maxalloc = tp->tp_allocs - tp->tp_frees; -} - -void _Py_dec_count(PyTypeObject *tp) -{ - tp->tp_frees++; - if (unlist_types_without_objects && - tp->tp_allocs == tp->tp_frees) { - /* unlink the type from type_list */ - if (tp->tp_prev) - tp->tp_prev->tp_next = tp->tp_next; - else - type_list = tp->tp_next; - if (tp->tp_next) - tp->tp_next->tp_prev = tp->tp_prev; - tp->tp_next = tp->tp_prev = NULL; - Py_DECREF(tp); - } -} - -#endif - #ifdef Py_REF_DEBUG /* Log a fatal error; doesn't return. */ void @@ -349,15 +235,6 @@ PyObject_CallFinalizerFromDealloc(PyObject *self) /* If Py_REF_DEBUG, _Py_NewReference bumped _Py_RefTotal, so * we need to undo that. */ _Py_DEC_REFTOTAL; - /* If Py_TRACE_REFS, _Py_NewReference re-added self to the object - * chain, so no more to do there. - * If COUNT_ALLOCS, the original decref bumped tp_frees, and - * _Py_NewReference bumped tp_allocs: both of those need to be - * undone. */ -#ifdef COUNT_ALLOCS - --Py_TYPE(self)->tp_frees; - --Py_TYPE(self)->tp_allocs; -#endif return -1; } @@ -1970,7 +1847,6 @@ _Py_ForgetReference(PyObject *op) op->_ob_next->_ob_prev = op->_ob_prev; op->_ob_prev->_ob_next = op->_ob_next; op->_ob_next = op->_ob_prev = NULL; - _Py_INC_TPFREES(op); } /* Print all live objects. Because PyObject_Print is called, the @@ -2289,8 +2165,6 @@ _Py_Dealloc(PyObject *op) destructor dealloc = Py_TYPE(op)->tp_dealloc; #ifdef Py_TRACE_REFS _Py_ForgetReference(op); -#else - _Py_INC_TPFREES(op); #endif (*dealloc)(op); } diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index 08f7022..2708b9a 100644 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -28,43 +28,10 @@ class tuple "PyTupleObject *" "&PyTuple_Type" static PyTupleObject *free_list[PyTuple_MAXSAVESIZE]; static int numfree[PyTuple_MAXSAVESIZE]; #endif -#ifdef COUNT_ALLOCS -Py_ssize_t _Py_fast_tuple_allocs; -Py_ssize_t _Py_tuple_zero_allocs; -#endif - -/* Debug statistic to count GC tracking of tuples. - Please note that tuples are only untracked when considered by the GC, and - many of them will be dead before. Therefore, a tracking rate close to 100% - does not necessarily prove that the heuristic is inefficient. -*/ -#ifdef SHOW_TRACK_COUNT -static Py_ssize_t count_untracked = 0; -static Py_ssize_t count_tracked = 0; - -static void -show_track(void) -{ - PyInterpreterState *interp = _PyInterpreterState_Get(); - if (!interp->config.show_alloc_count) { - return; - } - - fprintf(stderr, "Tuples created: %" PY_FORMAT_SIZE_T "d\n", - count_tracked + count_untracked); - fprintf(stderr, "Tuples tracked by the GC: %" PY_FORMAT_SIZE_T - "d\n", count_tracked); - fprintf(stderr, "%.2f%% tuple tracking rate\n\n", - (100.0*count_tracked/(count_untracked+count_tracked))); -} -#endif static inline void tuple_gc_track(PyTupleObject *op) { -#ifdef SHOW_TRACK_COUNT - count_tracked++; -#endif _PyObject_GC_TRACK(op); } @@ -106,9 +73,6 @@ tuple_alloc(Py_ssize_t size) assert(size != 0); free_list[size] = (PyTupleObject *) op->ob_item[0]; numfree[size]--; -#ifdef COUNT_ALLOCS - _Py_fast_tuple_allocs++; -#endif /* Inline PyObject_InitVar */ #ifdef Py_TRACE_REFS Py_SIZE(op) = size; @@ -139,9 +103,6 @@ PyTuple_New(Py_ssize_t size) if (size == 0 && free_list[0]) { op = free_list[0]; Py_INCREF(op); -#ifdef COUNT_ALLOCS - _Py_tuple_zero_allocs++; -#endif return (PyObject *) op; } #endif @@ -227,10 +188,6 @@ _PyTuple_MaybeUntrack(PyObject *op) _PyObject_GC_MAY_BE_TRACKED(elt)) return; } -#ifdef SHOW_TRACK_COUNT - count_tracked--; - count_untracked++; -#endif _PyObject_GC_UNTRACK(op); } @@ -1001,9 +958,6 @@ _PyTuple_Fini(void) (void)PyTuple_ClearFreeList(); #endif -#ifdef SHOW_TRACK_COUNT - show_track(); -#endif } /*********************** Tuple Iterator **************************/ |