Mercurial > cpython-lru_cache-weakref
annotate Objects/obmalloc.c @ 27998:e27f58a50737 legacy-trunk
SF bug #690377: Dud footnote reference in distutils docs
| author | Raymond Hettinger <python@rcn.com> |
|---|---|
| date | Fri, 21 Feb 2003 02:47:09 +0000 |
| parents | 4f2d5174bd4a |
| children | 231a3510e246 |
| rev | line source |
|---|---|
|
22469
8d0061493c57
Build obmalloc.c directly instead of #include'ing from object.c.
Tim Peters <tim.peters@gmail.com>
parents:
22465
diff
changeset
|
1 #include "Python.h" |
|
8d0061493c57
Build obmalloc.c directly instead of #include'ing from object.c.
Tim Peters <tim.peters@gmail.com>
parents:
22465
diff
changeset
|
2 |
|
8d0061493c57
Build obmalloc.c directly instead of #include'ing from object.c.
Tim Peters <tim.peters@gmail.com>
parents:
22465
diff
changeset
|
3 #ifdef WITH_PYMALLOC |
|
8d0061493c57
Build obmalloc.c directly instead of #include'ing from object.c.
Tim Peters <tim.peters@gmail.com>
parents:
22465
diff
changeset
|
4 |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
5 /* An object allocator for Python. |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
6 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
7 Here is an introduction to the layers of the Python memory architecture, |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
8 showing where the object allocator is actually used (layer +2), It is |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
9 called for every object allocation and deallocation (PyObject_New/Del), |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
10 unless the object-specific allocators implement a proprietary allocation |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
11 scheme (ex.: ints use a simple free list). This is also the place where |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
12 the cyclic garbage collector operates selectively on container objects. |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
13 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
14 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
15 Object-specific allocators |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
16 _____ ______ ______ ________ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
17 [ int ] [ dict ] [ list ] ... [ string ] Python core | |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
18 +3 | <----- Object-specific memory -----> | <-- Non-object memory --> | |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
19 _______________________________ | | |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
20 [ Python's object allocator ] | | |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
21 +2 | ####### Object memory ####### | <------ Internal buffers ------> | |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
22 ______________________________________________________________ | |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
23 [ Python's raw memory allocator (PyMem_ API) ] | |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
24 +1 | <----- Python memory (under PyMem manager's control) ------> | | |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
25 __________________________________________________________________ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
26 [ Underlying general-purpose allocator (ex: C library malloc) ] |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
27 0 | <------ Virtual memory allocated for the python process -------> | |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
28 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
29 ========================================================================= |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
30 _______________________________________________________________________ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
31 [ OS-specific Virtual Memory Manager (VMM) ] |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
32 -1 | <--- Kernel dynamic storage allocation & management (page-based) ---> | |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
33 __________________________________ __________________________________ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
34 [ ] [ ] |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
35 -2 | <-- Physical memory: ROM/RAM --> | | <-- Secondary storage (swap) --> | |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
36 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
37 */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
38 /*==========================================================================*/ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
39 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
40 /* A fast, special-purpose memory allocator for small blocks, to be used |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
41 on top of a general-purpose malloc -- heavily based on previous art. */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
42 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
43 /* Vladimir Marangozov -- August 2000 */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
44 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
45 /* |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
46 * "Memory management is where the rubber meets the road -- if we do the wrong |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
47 * thing at any level, the results will not be good. And if we don't make the |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
48 * levels work well together, we are in serious trouble." (1) |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
49 * |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
50 * (1) Paul R. Wilson, Mark S. Johnstone, Michael Neely, and David Boles, |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
51 * "Dynamic Storage Allocation: A Survey and Critical Review", |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
52 * in Proc. 1995 Int'l. Workshop on Memory Management, September 1995. |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
53 */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
54 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
55 /* #undef WITH_MEMORY_LIMITS */ /* disable mem limit checks */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
56 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
57 /*==========================================================================*/ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
58 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
59 /* |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
60 * Allocation strategy abstract: |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
61 * |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
62 * For small requests, the allocator sub-allocates <Big> blocks of memory. |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
63 * Requests greater than 256 bytes are routed to the system's allocator. |
|
22470
0e4758ccfe2b
Just whitespace fiddling.
Tim Peters <tim.peters@gmail.com>
parents:
22469
diff
changeset
|
64 * |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
65 * Small requests are grouped in size classes spaced 8 bytes apart, due |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
66 * to the required valid alignment of the returned address. Requests of |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
67 * a particular size are serviced from memory pools of 4K (one VMM page). |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
68 * Pools are fragmented on demand and contain free lists of blocks of one |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
69 * particular size class. In other words, there is a fixed-size allocator |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
70 * for each size class. Free pools are shared by the different allocators |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
71 * thus minimizing the space reserved for a particular size class. |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
72 * |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
73 * This allocation strategy is a variant of what is known as "simple |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
74 * segregated storage based on array of free lists". The main drawback of |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
75 * simple segregated storage is that we might end up with lot of reserved |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
76 * memory for the different free lists, which degenerate in time. To avoid |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
77 * this, we partition each free list in pools and we share dynamically the |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
78 * reserved space between all free lists. This technique is quite efficient |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
79 * for memory intensive programs which allocate mainly small-sized blocks. |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
80 * |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
81 * For small requests we have the following table: |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
82 * |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
83 * Request in bytes Size of allocated block Size class idx |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
84 * ---------------------------------------------------------------- |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
85 * 1-8 8 0 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
86 * 9-16 16 1 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
87 * 17-24 24 2 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
88 * 25-32 32 3 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
89 * 33-40 40 4 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
90 * 41-48 48 5 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
91 * 49-56 56 6 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
92 * 57-64 64 7 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
93 * 65-72 72 8 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
94 * ... ... ... |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
95 * 241-248 248 30 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
96 * 249-256 256 31 |
|
22470
0e4758ccfe2b
Just whitespace fiddling.
Tim Peters <tim.peters@gmail.com>
parents:
22469
diff
changeset
|
97 * |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
98 * 0, 257 and up: routed to the underlying allocator. |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
99 */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
100 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
101 /*==========================================================================*/ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
102 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
103 /* |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
104 * -- Main tunable settings section -- |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
105 */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
106 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
107 /* |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
108 * Alignment of addresses returned to the user. 8-bytes alignment works |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
109 * on most current architectures (with 32-bit or 64-bit address busses). |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
110 * The alignment value is also used for grouping small requests in size |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
111 * classes spaced ALIGNMENT bytes apart. |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
112 * |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
113 * You shouldn't change this unless you know what you are doing. |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
114 */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
115 #define ALIGNMENT 8 /* must be 2^N */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
116 #define ALIGNMENT_SHIFT 3 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
117 #define ALIGNMENT_MASK (ALIGNMENT - 1) |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
118 |
|
22836
f1f57bf09092
Widespread, but mostly in _PyMalloc_Malloc: optimize away all expensive
Tim Peters <tim.peters@gmail.com>
parents:
22795
diff
changeset
|
119 /* Return the number of bytes in size class I, as a uint. */ |
|
f1f57bf09092
Widespread, but mostly in _PyMalloc_Malloc: optimize away all expensive
Tim Peters <tim.peters@gmail.com>
parents:
22795
diff
changeset
|
120 #define INDEX2SIZE(I) (((uint)(I) + 1) << ALIGNMENT_SHIFT) |
|
f1f57bf09092
Widespread, but mostly in _PyMalloc_Malloc: optimize away all expensive
Tim Peters <tim.peters@gmail.com>
parents:
22795
diff
changeset
|
121 |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
122 /* |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
123 * Max size threshold below which malloc requests are considered to be |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
124 * small enough in order to use preallocated memory pools. You can tune |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
125 * this value according to your application behaviour and memory needs. |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
126 * |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
127 * The following invariants must hold: |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
128 * 1) ALIGNMENT <= SMALL_REQUEST_THRESHOLD <= 256 |
| 22684 | 129 * 2) SMALL_REQUEST_THRESHOLD is evenly divisible by ALIGNMENT |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
130 * |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
131 * Although not required, for better performance and space efficiency, |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
132 * it is recommended that SMALL_REQUEST_THRESHOLD is set to a power of 2. |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
133 */ |
| 22684 | 134 #define SMALL_REQUEST_THRESHOLD 256 |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
135 #define NB_SMALL_SIZE_CLASSES (SMALL_REQUEST_THRESHOLD / ALIGNMENT) |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
136 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
137 /* |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
138 * The system's VMM page size can be obtained on most unices with a |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
139 * getpagesize() call or deduced from various header files. To make |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
140 * things simpler, we assume that it is 4K, which is OK for most systems. |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
141 * It is probably better if this is the native page size, but it doesn't |
|
25928
75756c8558bd
Patch #627105: Document that SYSTEM_PAGE_SIZE really should not be
Martin v. Löwis <martin@v.loewis.de>
parents:
25233
diff
changeset
|
142 * have to be. In theory, if SYSTEM_PAGE_SIZE is larger than the native page |
|
75756c8558bd
Patch #627105: Document that SYSTEM_PAGE_SIZE really should not be
Martin v. Löwis <martin@v.loewis.de>
parents:
25233
diff
changeset
|
143 * size, then `POOL_ADDR(p)->arenaindex' could rarely cause a segmentation |
|
75756c8558bd
Patch #627105: Document that SYSTEM_PAGE_SIZE really should not be
Martin v. Löwis <martin@v.loewis.de>
parents:
25233
diff
changeset
|
144 * violation fault. 4K is apparently OK for all the platforms that python |
|
75756c8558bd
Patch #627105: Document that SYSTEM_PAGE_SIZE really should not be
Martin v. Löwis <martin@v.loewis.de>
parents:
25233
diff
changeset
|
145 * currently targets. |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
146 */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
147 #define SYSTEM_PAGE_SIZE (4 * 1024) |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
148 #define SYSTEM_PAGE_SIZE_MASK (SYSTEM_PAGE_SIZE - 1) |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
149 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
150 /* |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
151 * Maximum amount of memory managed by the allocator for small requests. |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
152 */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
153 #ifdef WITH_MEMORY_LIMITS |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
154 #ifndef SMALL_MEMORY_LIMIT |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
155 #define SMALL_MEMORY_LIMIT (64 * 1024 * 1024) /* 64 MB -- more? */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
156 #endif |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
157 #endif |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
158 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
159 /* |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
160 * The allocator sub-allocates <Big> blocks of memory (called arenas) aligned |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
161 * on a page boundary. This is a reserved virtual address space for the |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
162 * current process (obtained through a malloc call). In no way this means |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
163 * that the memory arenas will be used entirely. A malloc(<Big>) is usually |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
164 * an address range reservation for <Big> bytes, unless all pages within this |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
165 * space are referenced subsequently. So malloc'ing big blocks and not using |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
166 * them does not mean "wasting memory". It's an addressable range wastage... |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
167 * |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
168 * Therefore, allocating arenas with malloc is not optimal, because there is |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
169 * some address space wastage, but this is the most portable way to request |
| 22684 | 170 * memory from the system across various platforms. |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
171 */ |
|
22686
f8bd930644aa
Now that we're no longer linking arenas together, there's no need to
Tim Peters <tim.peters@gmail.com>
parents:
22685
diff
changeset
|
172 #define ARENA_SIZE (256 << 10) /* 256KB */ |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
173 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
174 #ifdef WITH_MEMORY_LIMITS |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
175 #define MAX_ARENAS (SMALL_MEMORY_LIMIT / ARENA_SIZE) |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
176 #endif |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
177 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
178 /* |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
179 * Size of the pools used for small blocks. Should be a power of 2, |
|
22692
2c02cf278f02
It's once again thought safe to call the pymalloc free/realloc with an
Tim Peters <tim.peters@gmail.com>
parents:
22691
diff
changeset
|
180 * between 1K and SYSTEM_PAGE_SIZE, that is: 1k, 2k, 4k. |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
181 */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
182 #define POOL_SIZE SYSTEM_PAGE_SIZE /* must be 2^N */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
183 #define POOL_SIZE_MASK SYSTEM_PAGE_SIZE_MASK |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
184 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
185 /* |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
186 * -- End of tunable settings section -- |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
187 */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
188 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
189 /*==========================================================================*/ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
190 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
191 /* |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
192 * Locking |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
193 * |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
194 * To reduce lock contention, it would probably be better to refine the |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
195 * crude function locking with per size class locking. I'm not positive |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
196 * however, whether it's worth switching to such locking policy because |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
197 * of the performance penalty it might introduce. |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
198 * |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
199 * The following macros describe the simplest (should also be the fastest) |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
200 * lock object on a particular platform and the init/fini/lock/unlock |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
201 * operations on it. The locks defined here are not expected to be recursive |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
202 * because it is assumed that they will always be called in the order: |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
203 * INIT, [LOCK, UNLOCK]*, FINI. |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
204 */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
205 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
206 /* |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
207 * Python's threads are serialized, so object malloc locking is disabled. |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
208 */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
209 #define SIMPLELOCK_DECL(lock) /* simple lock declaration */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
210 #define SIMPLELOCK_INIT(lock) /* allocate (if needed) and initialize */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
211 #define SIMPLELOCK_FINI(lock) /* free/destroy an existing lock */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
212 #define SIMPLELOCK_LOCK(lock) /* acquire released lock */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
213 #define SIMPLELOCK_UNLOCK(lock) /* release acquired lock */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
214 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
215 /* |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
216 * Basic types |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
217 * I don't care if these are defined in <sys/types.h> or elsewhere. Axiom. |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
218 */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
219 #undef uchar |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
220 #define uchar unsigned char /* assuming == 8 bits */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
221 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
222 #undef uint |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
223 #define uint unsigned int /* assuming >= 16 bits */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
224 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
225 #undef ulong |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
226 #define ulong unsigned long /* assuming >= 32 bits */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
227 |
| 22684 | 228 #undef uptr |
| 229 #define uptr Py_uintptr_t | |
| 230 | |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
231 /* When you say memory, my mind reasons in terms of (pointers to) blocks */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
232 typedef uchar block; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
233 |
|
22836
f1f57bf09092
Widespread, but mostly in _PyMalloc_Malloc: optimize away all expensive
Tim Peters <tim.peters@gmail.com>
parents:
22795
diff
changeset
|
234 /* Pool for small blocks. */ |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
235 struct pool_header { |
|
17030
3ec500403f01
Identifiers matching _[A-Z_]\w* are reserved for C implementations.
Tim Peters <tim.peters@gmail.com>
parents:
16782
diff
changeset
|
236 union { block *_padding; |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
237 uint count; } ref; /* number of allocated blocks */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
238 block *freeblock; /* pool's free list head */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
239 struct pool_header *nextpool; /* next pool of this size class */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
240 struct pool_header *prevpool; /* previous pool "" */ |
|
22690
00b2972ab4a4
Changed the #-of-arenas counters to uints -- no need to be insane about
Tim Peters <tim.peters@gmail.com>
parents:
22687
diff
changeset
|
241 uint arenaindex; /* index into arenas of base adr */ |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
242 uint szidx; /* block size class index */ |
|
22836
f1f57bf09092
Widespread, but mostly in _PyMalloc_Malloc: optimize away all expensive
Tim Peters <tim.peters@gmail.com>
parents:
22795
diff
changeset
|
243 uint nextoffset; /* bytes to virgin block */ |
|
f1f57bf09092
Widespread, but mostly in _PyMalloc_Malloc: optimize away all expensive
Tim Peters <tim.peters@gmail.com>
parents:
22795
diff
changeset
|
244 uint maxnextoffset; /* largest valid nextoffset */ |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
245 }; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
246 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
247 typedef struct pool_header *poolp; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
248 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
249 #undef ROUNDUP |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
250 #define ROUNDUP(x) (((x) + ALIGNMENT_MASK) & ~ALIGNMENT_MASK) |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
251 #define POOL_OVERHEAD ROUNDUP(sizeof(struct pool_header)) |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
252 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
253 #define DUMMY_SIZE_IDX 0xffff /* size class of newly cached pools */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
254 |
| 22684 | 255 /* Round pointer P down to the closest pool-aligned address <= P, as a poolp */ |
|
22836
f1f57bf09092
Widespread, but mostly in _PyMalloc_Malloc: optimize away all expensive
Tim Peters <tim.peters@gmail.com>
parents:
22795
diff
changeset
|
256 #define POOL_ADDR(P) ((poolp)((uptr)(P) & ~(uptr)POOL_SIZE_MASK)) |
|
f1f57bf09092
Widespread, but mostly in _PyMalloc_Malloc: optimize away all expensive
Tim Peters <tim.peters@gmail.com>
parents:
22795
diff
changeset
|
257 |
|
22837
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
258 /* Return total number of blocks in pool of size index I, as a uint. */ |
|
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
259 #define NUMBLOCKS(I) ((uint)(POOL_SIZE - POOL_OVERHEAD) / INDEX2SIZE(I)) |
| 22684 | 260 |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
261 /*==========================================================================*/ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
262 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
263 /* |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
264 * This malloc lock |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
265 */ |
|
24294
0a08ed05bd42
Remove extraneous semicolon.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24177
diff
changeset
|
266 SIMPLELOCK_DECL(_malloc_lock) |
|
17030
3ec500403f01
Identifiers matching _[A-Z_]\w* are reserved for C implementations.
Tim Peters <tim.peters@gmail.com>
parents:
16782
diff
changeset
|
267 #define LOCK() SIMPLELOCK_LOCK(_malloc_lock) |
|
3ec500403f01
Identifiers matching _[A-Z_]\w* are reserved for C implementations.
Tim Peters <tim.peters@gmail.com>
parents:
16782
diff
changeset
|
268 #define UNLOCK() SIMPLELOCK_UNLOCK(_malloc_lock) |
|
3ec500403f01
Identifiers matching _[A-Z_]\w* are reserved for C implementations.
Tim Peters <tim.peters@gmail.com>
parents:
16782
diff
changeset
|
269 #define LOCK_INIT() SIMPLELOCK_INIT(_malloc_lock) |
|
3ec500403f01
Identifiers matching _[A-Z_]\w* are reserved for C implementations.
Tim Peters <tim.peters@gmail.com>
parents:
16782
diff
changeset
|
270 #define LOCK_FINI() SIMPLELOCK_FINI(_malloc_lock) |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
271 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
272 /* |
|
22697
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
273 * Pool table -- headed, circular, doubly-linked lists of partially used pools. |
|
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
274 |
|
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
275 This is involved. For an index i, usedpools[i+i] is the header for a list of |
|
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
276 all partially used pools holding small blocks with "size class idx" i. So |
|
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
277 usedpools[0] corresponds to blocks of size 8, usedpools[2] to blocks of size |
|
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
278 16, and so on: index 2*i <-> blocks of size (i+1)<<ALIGNMENT_SHIFT. |
|
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
279 |
|
22741
771b2a8d445d
Restructured my pool-management overview in terms of the three
Tim Peters <tim.peters@gmail.com>
parents:
22724
diff
changeset
|
280 Pools are carved off the current arena highwater mark (file static arenabase) |
|
771b2a8d445d
Restructured my pool-management overview in terms of the three
Tim Peters <tim.peters@gmail.com>
parents:
22724
diff
changeset
|
281 as needed. Once carved off, a pool is in one of three states forever after: |
|
22697
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
282 |
|
22741
771b2a8d445d
Restructured my pool-management overview in terms of the three
Tim Peters <tim.peters@gmail.com>
parents:
22724
diff
changeset
|
283 used == partially used, neither empty nor full |
|
771b2a8d445d
Restructured my pool-management overview in terms of the three
Tim Peters <tim.peters@gmail.com>
parents:
22724
diff
changeset
|
284 At least one block in the pool is currently allocated, and at least one |
|
771b2a8d445d
Restructured my pool-management overview in terms of the three
Tim Peters <tim.peters@gmail.com>
parents:
22724
diff
changeset
|
285 block in the pool is not currently allocated (note this implies a pool |
|
771b2a8d445d
Restructured my pool-management overview in terms of the three
Tim Peters <tim.peters@gmail.com>
parents:
22724
diff
changeset
|
286 has room for at least two blocks). |
|
771b2a8d445d
Restructured my pool-management overview in terms of the three
Tim Peters <tim.peters@gmail.com>
parents:
22724
diff
changeset
|
287 This is a pool's initial state, as a pool is created only when malloc |
|
771b2a8d445d
Restructured my pool-management overview in terms of the three
Tim Peters <tim.peters@gmail.com>
parents:
22724
diff
changeset
|
288 needs space. |
|
771b2a8d445d
Restructured my pool-management overview in terms of the three
Tim Peters <tim.peters@gmail.com>
parents:
22724
diff
changeset
|
289 The pool holds blocks of a fixed size, and is in the circular list headed |
|
771b2a8d445d
Restructured my pool-management overview in terms of the three
Tim Peters <tim.peters@gmail.com>
parents:
22724
diff
changeset
|
290 at usedpools[i] (see above). It's linked to the other used pools of the |
|
771b2a8d445d
Restructured my pool-management overview in terms of the three
Tim Peters <tim.peters@gmail.com>
parents:
22724
diff
changeset
|
291 same size class via the pool_header's nextpool and prevpool members. |
|
771b2a8d445d
Restructured my pool-management overview in terms of the three
Tim Peters <tim.peters@gmail.com>
parents:
22724
diff
changeset
|
292 If all but one block is currently allocated, a malloc can cause a |
|
771b2a8d445d
Restructured my pool-management overview in terms of the three
Tim Peters <tim.peters@gmail.com>
parents:
22724
diff
changeset
|
293 transition to the full state. If all but one block is not currently |
|
771b2a8d445d
Restructured my pool-management overview in terms of the three
Tim Peters <tim.peters@gmail.com>
parents:
22724
diff
changeset
|
294 allocated, a free can cause a transition to the empty state. |
|
771b2a8d445d
Restructured my pool-management overview in terms of the three
Tim Peters <tim.peters@gmail.com>
parents:
22724
diff
changeset
|
295 |
|
771b2a8d445d
Restructured my pool-management overview in terms of the three
Tim Peters <tim.peters@gmail.com>
parents:
22724
diff
changeset
|
296 full == all the pool's blocks are currently allocated |
|
771b2a8d445d
Restructured my pool-management overview in terms of the three
Tim Peters <tim.peters@gmail.com>
parents:
22724
diff
changeset
|
297 On transition to full, a pool is unlinked from its usedpools[] list. |
|
771b2a8d445d
Restructured my pool-management overview in terms of the three
Tim Peters <tim.peters@gmail.com>
parents:
22724
diff
changeset
|
298 It's not linked to from anything then anymore, and its nextpool and |
|
771b2a8d445d
Restructured my pool-management overview in terms of the three
Tim Peters <tim.peters@gmail.com>
parents:
22724
diff
changeset
|
299 prevpool members are meaningless until it transitions back to used. |
|
771b2a8d445d
Restructured my pool-management overview in terms of the three
Tim Peters <tim.peters@gmail.com>
parents:
22724
diff
changeset
|
300 A free of a block in a full pool puts the pool back in the used state. |
|
771b2a8d445d
Restructured my pool-management overview in terms of the three
Tim Peters <tim.peters@gmail.com>
parents:
22724
diff
changeset
|
301 Then it's linked in at the front of the appropriate usedpools[] list, so |
|
771b2a8d445d
Restructured my pool-management overview in terms of the three
Tim Peters <tim.peters@gmail.com>
parents:
22724
diff
changeset
|
302 that the next allocation for its size class will reuse the freed block. |
|
22697
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
303 |
|
22741
771b2a8d445d
Restructured my pool-management overview in terms of the three
Tim Peters <tim.peters@gmail.com>
parents:
22724
diff
changeset
|
304 empty == all the pool's blocks are currently available for allocation |
|
771b2a8d445d
Restructured my pool-management overview in terms of the three
Tim Peters <tim.peters@gmail.com>
parents:
22724
diff
changeset
|
305 On transition to empty, a pool is unlinked from its usedpools[] list, |
|
771b2a8d445d
Restructured my pool-management overview in terms of the three
Tim Peters <tim.peters@gmail.com>
parents:
22724
diff
changeset
|
306 and linked to the front of the (file static) singly-linked freepools list, |
|
771b2a8d445d
Restructured my pool-management overview in terms of the three
Tim Peters <tim.peters@gmail.com>
parents:
22724
diff
changeset
|
307 via its nextpool member. The prevpool member has no meaning in this case. |
|
771b2a8d445d
Restructured my pool-management overview in terms of the three
Tim Peters <tim.peters@gmail.com>
parents:
22724
diff
changeset
|
308 Empty pools have no inherent size class: the next time a malloc finds |
|
771b2a8d445d
Restructured my pool-management overview in terms of the three
Tim Peters <tim.peters@gmail.com>
parents:
22724
diff
changeset
|
309 an empty list in usedpools[], it takes the first pool off of freepools. |
|
771b2a8d445d
Restructured my pool-management overview in terms of the three
Tim Peters <tim.peters@gmail.com>
parents:
22724
diff
changeset
|
310 If the size class needed happens to be the same as the size class the pool |
|
22836
f1f57bf09092
Widespread, but mostly in _PyMalloc_Malloc: optimize away all expensive
Tim Peters <tim.peters@gmail.com>
parents:
22795
diff
changeset
|
311 last had, some pool initialization can be skipped. |
|
22741
771b2a8d445d
Restructured my pool-management overview in terms of the three
Tim Peters <tim.peters@gmail.com>
parents:
22724
diff
changeset
|
312 |
|
771b2a8d445d
Restructured my pool-management overview in terms of the three
Tim Peters <tim.peters@gmail.com>
parents:
22724
diff
changeset
|
313 |
|
771b2a8d445d
Restructured my pool-management overview in terms of the three
Tim Peters <tim.peters@gmail.com>
parents:
22724
diff
changeset
|
314 Block Management |
|
771b2a8d445d
Restructured my pool-management overview in terms of the three
Tim Peters <tim.peters@gmail.com>
parents:
22724
diff
changeset
|
315 |
|
771b2a8d445d
Restructured my pool-management overview in terms of the three
Tim Peters <tim.peters@gmail.com>
parents:
22724
diff
changeset
|
316 Blocks within pools are again carved out as needed. pool->freeblock points to |
|
771b2a8d445d
Restructured my pool-management overview in terms of the three
Tim Peters <tim.peters@gmail.com>
parents:
22724
diff
changeset
|
317 the start of a singly-linked list of free blocks within the pool. When a |
|
771b2a8d445d
Restructured my pool-management overview in terms of the three
Tim Peters <tim.peters@gmail.com>
parents:
22724
diff
changeset
|
318 block is freed, it's inserted at the front of its pool's freeblock list. Note |
|
771b2a8d445d
Restructured my pool-management overview in terms of the three
Tim Peters <tim.peters@gmail.com>
parents:
22724
diff
changeset
|
319 that the available blocks in a pool are *not* linked all together when a pool |
|
22836
f1f57bf09092
Widespread, but mostly in _PyMalloc_Malloc: optimize away all expensive
Tim Peters <tim.peters@gmail.com>
parents:
22795
diff
changeset
|
320 is initialized. Instead only "the first two" (lowest addresses) blocks are |
|
f1f57bf09092
Widespread, but mostly in _PyMalloc_Malloc: optimize away all expensive
Tim Peters <tim.peters@gmail.com>
parents:
22795
diff
changeset
|
321 set up, returning the first such block, and setting pool->freeblock to a |
|
f1f57bf09092
Widespread, but mostly in _PyMalloc_Malloc: optimize away all expensive
Tim Peters <tim.peters@gmail.com>
parents:
22795
diff
changeset
|
322 one-block list holding the second such block. This is consistent with that |
|
f1f57bf09092
Widespread, but mostly in _PyMalloc_Malloc: optimize away all expensive
Tim Peters <tim.peters@gmail.com>
parents:
22795
diff
changeset
|
323 pymalloc strives at all levels (arena, pool, and block) never to touch a piece |
|
f1f57bf09092
Widespread, but mostly in _PyMalloc_Malloc: optimize away all expensive
Tim Peters <tim.peters@gmail.com>
parents:
22795
diff
changeset
|
324 of memory until it's actually needed. |
|
f1f57bf09092
Widespread, but mostly in _PyMalloc_Malloc: optimize away all expensive
Tim Peters <tim.peters@gmail.com>
parents:
22795
diff
changeset
|
325 |
|
f1f57bf09092
Widespread, but mostly in _PyMalloc_Malloc: optimize away all expensive
Tim Peters <tim.peters@gmail.com>
parents:
22795
diff
changeset
|
326 So long as a pool is in the used state, we're certain there *is* a block |
|
22948
6cb52829da1a
SF bug 542181: Realloc behavior
Tim Peters <tim.peters@gmail.com>
parents:
22860
diff
changeset
|
327 available for allocating, and pool->freeblock is not NULL. If pool->freeblock |
|
6cb52829da1a
SF bug 542181: Realloc behavior
Tim Peters <tim.peters@gmail.com>
parents:
22860
diff
changeset
|
328 points to the end of the free list before we've carved the entire pool into |
|
6cb52829da1a
SF bug 542181: Realloc behavior
Tim Peters <tim.peters@gmail.com>
parents:
22860
diff
changeset
|
329 blocks, that means we simply haven't yet gotten to one of the higher-address |
|
6cb52829da1a
SF bug 542181: Realloc behavior
Tim Peters <tim.peters@gmail.com>
parents:
22860
diff
changeset
|
330 blocks. The offset from the pool_header to the start of "the next" virgin |
|
6cb52829da1a
SF bug 542181: Realloc behavior
Tim Peters <tim.peters@gmail.com>
parents:
22860
diff
changeset
|
331 block is stored in the pool_header nextoffset member, and the largest value |
|
6cb52829da1a
SF bug 542181: Realloc behavior
Tim Peters <tim.peters@gmail.com>
parents:
22860
diff
changeset
|
332 of nextoffset that makes sense is stored in the maxnextoffset member when a |
|
6cb52829da1a
SF bug 542181: Realloc behavior
Tim Peters <tim.peters@gmail.com>
parents:
22860
diff
changeset
|
333 pool is initialized. All the blocks in a pool have been passed out at least |
|
6cb52829da1a
SF bug 542181: Realloc behavior
Tim Peters <tim.peters@gmail.com>
parents:
22860
diff
changeset
|
334 once when and only when nextoffset > maxnextoffset. |
|
22741
771b2a8d445d
Restructured my pool-management overview in terms of the three
Tim Peters <tim.peters@gmail.com>
parents:
22724
diff
changeset
|
335 |
|
22697
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
336 |
|
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
337 Major obscurity: While the usedpools vector is declared to have poolp |
|
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
338 entries, it doesn't really. It really contains two pointers per (conceptual) |
|
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
339 poolp entry, the nextpool and prevpool members of a pool_header. The |
|
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
340 excruciating initialization code below fools C so that |
|
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
341 |
|
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
342 usedpool[i+i] |
|
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
343 |
|
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
344 "acts like" a genuine poolp, but only so long as you only reference its |
|
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
345 nextpool and prevpool members. The "- 2*sizeof(block *)" gibberish is |
|
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
346 compensating for that a pool_header's nextpool and prevpool members |
|
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
347 immediately follow a pool_header's first two members: |
|
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
348 |
|
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
349 union { block *_padding; |
|
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
350 uint count; } ref; |
|
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
351 block *freeblock; |
|
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
352 |
|
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
353 each of which consume sizeof(block *) bytes. So what usedpools[i+i] really |
|
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
354 contains is a fudged-up pointer p such that *if* C believes it's a poolp |
|
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
355 pointer, then p->nextpool and p->prevpool are both p (meaning that the headed |
|
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
356 circular list is empty). |
|
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
357 |
|
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
358 It's unclear why the usedpools setup is so convoluted. It could be to |
|
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
359 minimize the amount of cache required to hold this heavily-referenced table |
|
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
360 (which only *needs* the two interpool pointer members of a pool_header). OTOH, |
|
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
361 referencing code has to remember to "double the index" and doing so isn't |
|
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
362 free, usedpools[0] isn't a strictly legal pointer, and we're crucially relying |
|
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
363 on that C doesn't insert any padding anywhere in a pool_header at or before |
|
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
364 the prevpool member. |
|
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
365 **************************************************************************** */ |
|
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
366 |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
367 #define PTA(x) ((poolp )((uchar *)&(usedpools[2*(x)]) - 2*sizeof(block *))) |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
368 #define PT(x) PTA(x), PTA(x) |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
369 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
370 static poolp usedpools[2 * ((NB_SMALL_SIZE_CLASSES + 7) / 8) * 8] = { |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
371 PT(0), PT(1), PT(2), PT(3), PT(4), PT(5), PT(6), PT(7) |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
372 #if NB_SMALL_SIZE_CLASSES > 8 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
373 , PT(8), PT(9), PT(10), PT(11), PT(12), PT(13), PT(14), PT(15) |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
374 #if NB_SMALL_SIZE_CLASSES > 16 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
375 , PT(16), PT(17), PT(18), PT(19), PT(20), PT(21), PT(22), PT(23) |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
376 #if NB_SMALL_SIZE_CLASSES > 24 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
377 , PT(24), PT(25), PT(26), PT(27), PT(28), PT(29), PT(30), PT(31) |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
378 #if NB_SMALL_SIZE_CLASSES > 32 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
379 , PT(32), PT(33), PT(34), PT(35), PT(36), PT(37), PT(38), PT(39) |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
380 #if NB_SMALL_SIZE_CLASSES > 40 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
381 , PT(40), PT(41), PT(42), PT(43), PT(44), PT(45), PT(46), PT(47) |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
382 #if NB_SMALL_SIZE_CLASSES > 48 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
383 , PT(48), PT(49), PT(50), PT(51), PT(52), PT(53), PT(54), PT(55) |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
384 #if NB_SMALL_SIZE_CLASSES > 56 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
385 , PT(56), PT(57), PT(58), PT(59), PT(60), PT(61), PT(62), PT(63) |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
386 #endif /* NB_SMALL_SIZE_CLASSES > 56 */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
387 #endif /* NB_SMALL_SIZE_CLASSES > 48 */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
388 #endif /* NB_SMALL_SIZE_CLASSES > 40 */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
389 #endif /* NB_SMALL_SIZE_CLASSES > 32 */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
390 #endif /* NB_SMALL_SIZE_CLASSES > 24 */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
391 #endif /* NB_SMALL_SIZE_CLASSES > 16 */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
392 #endif /* NB_SMALL_SIZE_CLASSES > 8 */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
393 }; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
394 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
395 /* |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
396 * Free (cached) pools |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
397 */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
398 static poolp freepools = NULL; /* free list for cached pools */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
399 |
| 22684 | 400 /*==========================================================================*/ |
| 401 /* Arena management. */ | |
| 402 | |
| 403 /* arenas is a vector of arena base addresses, in order of allocation time. | |
| 404 * arenas currently contains narenas entries, and has space allocated | |
| 405 * for at most maxarenas entries. | |
| 406 * | |
| 407 * CAUTION: See the long comment block about thread safety in new_arena(): | |
| 408 * the code currently relies in deep ways on that this vector only grows, | |
| 409 * and only grows by appending at the end. For now we never return an arena | |
| 410 * to the OS. | |
| 411 */ | |
|
22692
2c02cf278f02
It's once again thought safe to call the pymalloc free/realloc with an
Tim Peters <tim.peters@gmail.com>
parents:
22691
diff
changeset
|
412 static uptr *volatile arenas = NULL; /* the pointer itself is volatile */ |
|
2c02cf278f02
It's once again thought safe to call the pymalloc free/realloc with an
Tim Peters <tim.peters@gmail.com>
parents:
22691
diff
changeset
|
413 static volatile uint narenas = 0; |
|
22690
00b2972ab4a4
Changed the #-of-arenas counters to uints -- no need to be insane about
Tim Peters <tim.peters@gmail.com>
parents:
22687
diff
changeset
|
414 static uint maxarenas = 0; |
| 22684 | 415 |
|
22686
f8bd930644aa
Now that we're no longer linking arenas together, there's no need to
Tim Peters <tim.peters@gmail.com>
parents:
22685
diff
changeset
|
416 /* Number of pools still available to be allocated in the current arena. */ |
|
f8bd930644aa
Now that we're no longer linking arenas together, there's no need to
Tim Peters <tim.peters@gmail.com>
parents:
22685
diff
changeset
|
417 static uint nfreepools = 0; |
| 22684 | 418 |
|
22686
f8bd930644aa
Now that we're no longer linking arenas together, there's no need to
Tim Peters <tim.peters@gmail.com>
parents:
22685
diff
changeset
|
419 /* Free space start address in current arena. This is pool-aligned. */ |
| 22684 | 420 static block *arenabase = NULL; |
| 421 | |
| 422 /* Allocate a new arena and return its base address. If we run out of | |
| 423 * memory, return NULL. | |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
424 */ |
| 22684 | 425 static block * |
| 426 new_arena(void) | |
| 427 { | |
|
22686
f8bd930644aa
Now that we're no longer linking arenas together, there's no need to
Tim Peters <tim.peters@gmail.com>
parents:
22685
diff
changeset
|
428 uint excess; /* number of bytes above pool alignment */ |
|
22794
f663ffbe9e5c
_PyMalloc_{Malloc, Realloc}: Strive to meet the doc's promises about
Tim Peters <tim.peters@gmail.com>
parents:
22743
diff
changeset
|
429 block *bp = (block *)malloc(ARENA_SIZE); |
| 22684 | 430 if (bp == NULL) |
| 431 return NULL; | |
| 432 | |
|
23020
e2848618bd19
_PyObject_DebugDumpStats: renamed to _PyObject_DebugMallocStats.
Tim Peters <tim.peters@gmail.com>
parents:
23009
diff
changeset
|
433 #ifdef PYMALLOC_DEBUG |
|
e2848618bd19
_PyObject_DebugDumpStats: renamed to _PyObject_DebugMallocStats.
Tim Peters <tim.peters@gmail.com>
parents:
23009
diff
changeset
|
434 if (Py_GETENV("PYTHONMALLOCSTATS")) |
|
e2848618bd19
_PyObject_DebugDumpStats: renamed to _PyObject_DebugMallocStats.
Tim Peters <tim.peters@gmail.com>
parents:
23009
diff
changeset
|
435 _PyObject_DebugMallocStats(); |
|
e2848618bd19
_PyObject_DebugDumpStats: renamed to _PyObject_DebugMallocStats.
Tim Peters <tim.peters@gmail.com>
parents:
23009
diff
changeset
|
436 #endif |
|
e2848618bd19
_PyObject_DebugDumpStats: renamed to _PyObject_DebugMallocStats.
Tim Peters <tim.peters@gmail.com>
parents:
23009
diff
changeset
|
437 |
|
22686
f8bd930644aa
Now that we're no longer linking arenas together, there's no need to
Tim Peters <tim.peters@gmail.com>
parents:
22685
diff
changeset
|
438 /* arenabase <- first pool-aligned address in the arena |
|
f8bd930644aa
Now that we're no longer linking arenas together, there's no need to
Tim Peters <tim.peters@gmail.com>
parents:
22685
diff
changeset
|
439 nfreepools <- number of whole pools that fit after alignment */ |
|
f8bd930644aa
Now that we're no longer linking arenas together, there's no need to
Tim Peters <tim.peters@gmail.com>
parents:
22685
diff
changeset
|
440 arenabase = bp; |
|
f8bd930644aa
Now that we're no longer linking arenas together, there's no need to
Tim Peters <tim.peters@gmail.com>
parents:
22685
diff
changeset
|
441 nfreepools = ARENA_SIZE / POOL_SIZE; |
|
22692
2c02cf278f02
It's once again thought safe to call the pymalloc free/realloc with an
Tim Peters <tim.peters@gmail.com>
parents:
22691
diff
changeset
|
442 assert(POOL_SIZE * nfreepools == ARENA_SIZE); |
|
25233
8d751b62ecc4
Fix warnings on 64-bit platforms about casts from pointers to ints.
Guido van Rossum <guido@python.org>
parents:
24294
diff
changeset
|
443 excess = (uint) ((Py_uintptr_t)bp & POOL_SIZE_MASK); |
|
22686
f8bd930644aa
Now that we're no longer linking arenas together, there's no need to
Tim Peters <tim.peters@gmail.com>
parents:
22685
diff
changeset
|
444 if (excess != 0) { |
|
f8bd930644aa
Now that we're no longer linking arenas together, there's no need to
Tim Peters <tim.peters@gmail.com>
parents:
22685
diff
changeset
|
445 --nfreepools; |
|
f8bd930644aa
Now that we're no longer linking arenas together, there's no need to
Tim Peters <tim.peters@gmail.com>
parents:
22685
diff
changeset
|
446 arenabase += POOL_SIZE - excess; |
|
f8bd930644aa
Now that we're no longer linking arenas together, there's no need to
Tim Peters <tim.peters@gmail.com>
parents:
22685
diff
changeset
|
447 } |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
448 |
| 22684 | 449 /* Make room for a new entry in the arenas vector. */ |
| 450 if (arenas == NULL) { | |
|
22692
2c02cf278f02
It's once again thought safe to call the pymalloc free/realloc with an
Tim Peters <tim.peters@gmail.com>
parents:
22691
diff
changeset
|
451 assert(narenas == 0 && maxarenas == 0); |
|
22794
f663ffbe9e5c
_PyMalloc_{Malloc, Realloc}: Strive to meet the doc's promises about
Tim Peters <tim.peters@gmail.com>
parents:
22743
diff
changeset
|
452 arenas = (uptr *)malloc(16 * sizeof(*arenas)); |
| 22684 | 453 if (arenas == NULL) |
| 454 goto error; | |
| 455 maxarenas = 16; | |
| 456 } | |
| 457 else if (narenas == maxarenas) { | |
|
22948
6cb52829da1a
SF bug 542181: Realloc behavior
Tim Peters <tim.peters@gmail.com>
parents:
22860
diff
changeset
|
458 /* Grow arenas. |
|
22692
2c02cf278f02
It's once again thought safe to call the pymalloc free/realloc with an
Tim Peters <tim.peters@gmail.com>
parents:
22691
diff
changeset
|
459 * |
| 22684 | 460 * Exceedingly subtle: Someone may be calling the pymalloc |
| 461 * free via PyMem_{DEL, Del, FREE, Free} without holding the | |
| 462 *.GIL. Someone else may simultaneously be calling the | |
| 463 * pymalloc malloc while holding the GIL via, e.g., | |
| 464 * PyObject_New. Now the pymalloc free may index into arenas | |
| 465 * for an address check, while the pymalloc malloc calls | |
| 466 * new_arena and we end up here to grow a new arena *and* | |
| 467 * grow the arenas vector. If the value for arenas pymalloc | |
| 468 * free picks up "vanishes" during this resize, anything may | |
| 469 * happen, and it would be an incredibly rare bug. Therefore | |
| 470 * the code here takes great pains to make sure that, at every | |
| 471 * moment, arenas always points to an intact vector of | |
| 472 * addresses. It doesn't matter whether arenas points to a | |
| 473 * wholly up-to-date vector when pymalloc free checks it in | |
| 474 * this case, because the only legal (and that even this is | |
| 475 * legal is debatable) way to call PyMem_{Del, etc} while not | |
| 476 * holding the GIL is if the memory being released is not | |
| 477 * object memory, i.e. if the address check in pymalloc free | |
| 478 * is supposed to fail. Having an incomplete vector can't | |
| 479 * make a supposed-to-fail case succeed by mistake (it could | |
| 480 * only make a supposed-to-succeed case fail by mistake). | |
|
22692
2c02cf278f02
It's once again thought safe to call the pymalloc free/realloc with an
Tim Peters <tim.peters@gmail.com>
parents:
22691
diff
changeset
|
481 * |
|
2c02cf278f02
It's once again thought safe to call the pymalloc free/realloc with an
Tim Peters <tim.peters@gmail.com>
parents:
22691
diff
changeset
|
482 * In addition, without a lock we can't know for sure when |
|
2c02cf278f02
It's once again thought safe to call the pymalloc free/realloc with an
Tim Peters <tim.peters@gmail.com>
parents:
22691
diff
changeset
|
483 * an old vector is no longer referenced, so we simply let |
|
2c02cf278f02
It's once again thought safe to call the pymalloc free/realloc with an
Tim Peters <tim.peters@gmail.com>
parents:
22691
diff
changeset
|
484 * old vectors leak. |
|
2c02cf278f02
It's once again thought safe to call the pymalloc free/realloc with an
Tim Peters <tim.peters@gmail.com>
parents:
22691
diff
changeset
|
485 * |
|
2c02cf278f02
It's once again thought safe to call the pymalloc free/realloc with an
Tim Peters <tim.peters@gmail.com>
parents:
22691
diff
changeset
|
486 * And on top of that, since narenas and arenas can't be |
|
2c02cf278f02
It's once again thought safe to call the pymalloc free/realloc with an
Tim Peters <tim.peters@gmail.com>
parents:
22691
diff
changeset
|
487 * changed as-a-pair atomically without a lock, we're also |
|
2c02cf278f02
It's once again thought safe to call the pymalloc free/realloc with an
Tim Peters <tim.peters@gmail.com>
parents:
22691
diff
changeset
|
488 * careful to declare them volatile and ensure that we change |
|
2c02cf278f02
It's once again thought safe to call the pymalloc free/realloc with an
Tim Peters <tim.peters@gmail.com>
parents:
22691
diff
changeset
|
489 * arenas first. This prevents another thread from picking |
|
2c02cf278f02
It's once again thought safe to call the pymalloc free/realloc with an
Tim Peters <tim.peters@gmail.com>
parents:
22691
diff
changeset
|
490 * up an narenas value too large for the arenas value it |
|
2c02cf278f02
It's once again thought safe to call the pymalloc free/realloc with an
Tim Peters <tim.peters@gmail.com>
parents:
22691
diff
changeset
|
491 * reads up (arenas never shrinks). |
|
2c02cf278f02
It's once again thought safe to call the pymalloc free/realloc with an
Tim Peters <tim.peters@gmail.com>
parents:
22691
diff
changeset
|
492 * |
| 22684 | 493 * Read the above 50 times before changing anything in this |
| 494 * block. | |
| 495 */ | |
|
22690
00b2972ab4a4
Changed the #-of-arenas counters to uints -- no need to be insane about
Tim Peters <tim.peters@gmail.com>
parents:
22687
diff
changeset
|
496 uptr *p; |
|
22692
2c02cf278f02
It's once again thought safe to call the pymalloc free/realloc with an
Tim Peters <tim.peters@gmail.com>
parents:
22691
diff
changeset
|
497 uint newmax = maxarenas << 1; |
|
22690
00b2972ab4a4
Changed the #-of-arenas counters to uints -- no need to be insane about
Tim Peters <tim.peters@gmail.com>
parents:
22687
diff
changeset
|
498 if (newmax <= maxarenas) /* overflow */ |
|
00b2972ab4a4
Changed the #-of-arenas counters to uints -- no need to be insane about
Tim Peters <tim.peters@gmail.com>
parents:
22687
diff
changeset
|
499 goto error; |
|
22794
f663ffbe9e5c
_PyMalloc_{Malloc, Realloc}: Strive to meet the doc's promises about
Tim Peters <tim.peters@gmail.com>
parents:
22743
diff
changeset
|
500 p = (uptr *)malloc(newmax * sizeof(*arenas)); |
| 22684 | 501 if (p == NULL) |
| 502 goto error; | |
| 503 memcpy(p, arenas, narenas * sizeof(*arenas)); | |
|
22692
2c02cf278f02
It's once again thought safe to call the pymalloc free/realloc with an
Tim Peters <tim.peters@gmail.com>
parents:
22691
diff
changeset
|
504 arenas = p; /* old arenas deliberately leaked */ |
| 22684 | 505 maxarenas = newmax; |
| 506 } | |
| 507 | |
| 508 /* Append the new arena address to arenas. */ | |
| 509 assert(narenas < maxarenas); | |
| 510 arenas[narenas] = (uptr)bp; | |
|
22690
00b2972ab4a4
Changed the #-of-arenas counters to uints -- no need to be insane about
Tim Peters <tim.peters@gmail.com>
parents:
22687
diff
changeset
|
511 ++narenas; /* can't overflow, since narenas < maxarenas before */ |
| 22684 | 512 return bp; |
| 513 | |
| 514 error: | |
|
22794
f663ffbe9e5c
_PyMalloc_{Malloc, Realloc}: Strive to meet the doc's promises about
Tim Peters <tim.peters@gmail.com>
parents:
22743
diff
changeset
|
515 free(bp); |
|
22691
5ae3c31673e4
new_arena(): In error cases, reset the number of available pools to 0.
Tim Peters <tim.peters@gmail.com>
parents:
22690
diff
changeset
|
516 nfreepools = 0; |
| 22684 | 517 return NULL; |
| 518 } | |
| 519 | |
| 520 /* Return true if and only if P is an address that was allocated by | |
| 521 * pymalloc. I must be the index into arenas that the address claims | |
| 522 * to come from. | |
|
22692
2c02cf278f02
It's once again thought safe to call the pymalloc free/realloc with an
Tim Peters <tim.peters@gmail.com>
parents:
22691
diff
changeset
|
523 * |
| 22684 | 524 * Tricky: Letting B be the arena base address in arenas[I], P belongs to the |
| 525 * arena if and only if | |
|
22686
f8bd930644aa
Now that we're no longer linking arenas together, there's no need to
Tim Peters <tim.peters@gmail.com>
parents:
22685
diff
changeset
|
526 * B <= P < B + ARENA_SIZE |
| 22684 | 527 * Subtracting B throughout, this is true iff |
|
22686
f8bd930644aa
Now that we're no longer linking arenas together, there's no need to
Tim Peters <tim.peters@gmail.com>
parents:
22685
diff
changeset
|
528 * 0 <= P-B < ARENA_SIZE |
| 22684 | 529 * By using unsigned arithmetic, the "0 <=" half of the test can be skipped. |
|
22692
2c02cf278f02
It's once again thought safe to call the pymalloc free/realloc with an
Tim Peters <tim.peters@gmail.com>
parents:
22691
diff
changeset
|
530 * |
|
2c02cf278f02
It's once again thought safe to call the pymalloc free/realloc with an
Tim Peters <tim.peters@gmail.com>
parents:
22691
diff
changeset
|
531 * Obscure: A PyMem "free memory" function can call the pymalloc free or |
|
2c02cf278f02
It's once again thought safe to call the pymalloc free/realloc with an
Tim Peters <tim.peters@gmail.com>
parents:
22691
diff
changeset
|
532 * realloc before the first arena has been allocated. arenas is still |
|
2c02cf278f02
It's once again thought safe to call the pymalloc free/realloc with an
Tim Peters <tim.peters@gmail.com>
parents:
22691
diff
changeset
|
533 * NULL in that case. We're relying on that narenas is also 0 in that case, |
|
2c02cf278f02
It's once again thought safe to call the pymalloc free/realloc with an
Tim Peters <tim.peters@gmail.com>
parents:
22691
diff
changeset
|
534 * so the (I) < narenas must be false, saving us from trying to index into |
|
2c02cf278f02
It's once again thought safe to call the pymalloc free/realloc with an
Tim Peters <tim.peters@gmail.com>
parents:
22691
diff
changeset
|
535 * a NULL arenas. |
| 22684 | 536 */ |
| 537 #define ADDRESS_IN_RANGE(P, I) \ | |
|
22686
f8bd930644aa
Now that we're no longer linking arenas together, there's no need to
Tim Peters <tim.peters@gmail.com>
parents:
22685
diff
changeset
|
538 ((I) < narenas && (uptr)(P) - arenas[I] < (uptr)ARENA_SIZE) |
|
22741
771b2a8d445d
Restructured my pool-management overview in terms of the three
Tim Peters <tim.peters@gmail.com>
parents:
22724
diff
changeset
|
539 |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
540 /*==========================================================================*/ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
541 |
|
22794
f663ffbe9e5c
_PyMalloc_{Malloc, Realloc}: Strive to meet the doc's promises about
Tim Peters <tim.peters@gmail.com>
parents:
22743
diff
changeset
|
542 /* malloc. Note that nbytes==0 tries to return a non-NULL pointer, distinct |
|
f663ffbe9e5c
_PyMalloc_{Malloc, Realloc}: Strive to meet the doc's promises about
Tim Peters <tim.peters@gmail.com>
parents:
22743
diff
changeset
|
543 * from all other currently live pointers. This may not be possible. |
|
f663ffbe9e5c
_PyMalloc_{Malloc, Realloc}: Strive to meet the doc's promises about
Tim Peters <tim.peters@gmail.com>
parents:
22743
diff
changeset
|
544 */ |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
545 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
546 /* |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
547 * The basic blocks are ordered by decreasing execution frequency, |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
548 * which minimizes the number of jumps in the most common cases, |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
549 * improves branching prediction and instruction scheduling (small |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
550 * block allocations typically result in a couple of instructions). |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
551 * Unless the optimizer reorders everything, being too smart... |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
552 */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
553 |
|
22983
1c26a3106653
Move PyObject_Malloc and PyObject_Free here from object.c. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22948
diff
changeset
|
554 #undef PyObject_Malloc |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
555 void * |
|
22983
1c26a3106653
Move PyObject_Malloc and PyObject_Free here from object.c. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22948
diff
changeset
|
556 PyObject_Malloc(size_t nbytes) |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
557 { |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
558 block *bp; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
559 poolp pool; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
560 poolp next; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
561 uint size; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
562 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
563 /* |
|
22794
f663ffbe9e5c
_PyMalloc_{Malloc, Realloc}: Strive to meet the doc's promises about
Tim Peters <tim.peters@gmail.com>
parents:
22743
diff
changeset
|
564 * This implicitly redirects malloc(0). |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
565 */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
566 if ((nbytes - 1) < SMALL_REQUEST_THRESHOLD) { |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
567 LOCK(); |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
568 /* |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
569 * Most frequent paths first |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
570 */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
571 size = (uint )(nbytes - 1) >> ALIGNMENT_SHIFT; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
572 pool = usedpools[size + size]; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
573 if (pool != pool->nextpool) { |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
574 /* |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
575 * There is a used pool for this size class. |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
576 * Pick up the head block of its free list. |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
577 */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
578 ++pool->ref.count; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
579 bp = pool->freeblock; |
|
22948
6cb52829da1a
SF bug 542181: Realloc behavior
Tim Peters <tim.peters@gmail.com>
parents:
22860
diff
changeset
|
580 assert(bp != NULL); |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
581 if ((pool->freeblock = *(block **)bp) != NULL) { |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
582 UNLOCK(); |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
583 return (void *)bp; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
584 } |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
585 /* |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
586 * Reached the end of the free list, try to extend it |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
587 */ |
|
22836
f1f57bf09092
Widespread, but mostly in _PyMalloc_Malloc: optimize away all expensive
Tim Peters <tim.peters@gmail.com>
parents:
22795
diff
changeset
|
588 if (pool->nextoffset <= pool->maxnextoffset) { |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
589 /* |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
590 * There is room for another block |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
591 */ |
|
22836
f1f57bf09092
Widespread, but mostly in _PyMalloc_Malloc: optimize away all expensive
Tim Peters <tim.peters@gmail.com>
parents:
22795
diff
changeset
|
592 pool->freeblock = (block *)pool + |
|
f1f57bf09092
Widespread, but mostly in _PyMalloc_Malloc: optimize away all expensive
Tim Peters <tim.peters@gmail.com>
parents:
22795
diff
changeset
|
593 pool->nextoffset; |
|
f1f57bf09092
Widespread, but mostly in _PyMalloc_Malloc: optimize away all expensive
Tim Peters <tim.peters@gmail.com>
parents:
22795
diff
changeset
|
594 pool->nextoffset += INDEX2SIZE(size); |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
595 *(block **)(pool->freeblock) = NULL; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
596 UNLOCK(); |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
597 return (void *)bp; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
598 } |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
599 /* |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
600 * Pool is full, unlink from used pools |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
601 */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
602 next = pool->nextpool; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
603 pool = pool->prevpool; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
604 next->prevpool = pool; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
605 pool->nextpool = next; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
606 UNLOCK(); |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
607 return (void *)bp; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
608 } |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
609 /* |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
610 * Try to get a cached free pool |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
611 */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
612 pool = freepools; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
613 if (pool != NULL) { |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
614 /* |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
615 * Unlink from cached pools |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
616 */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
617 freepools = pool->nextpool; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
618 init_pool: |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
619 /* |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
620 * Frontlink to used pools |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
621 */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
622 next = usedpools[size + size]; /* == prev */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
623 pool->nextpool = next; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
624 pool->prevpool = next; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
625 next->nextpool = pool; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
626 next->prevpool = pool; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
627 pool->ref.count = 1; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
628 if (pool->szidx == size) { |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
629 /* |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
630 * Luckily, this pool last contained blocks |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
631 * of the same size class, so its header |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
632 * and free list are already initialized. |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
633 */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
634 bp = pool->freeblock; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
635 pool->freeblock = *(block **)bp; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
636 UNLOCK(); |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
637 return (void *)bp; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
638 } |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
639 /* |
|
22836
f1f57bf09092
Widespread, but mostly in _PyMalloc_Malloc: optimize away all expensive
Tim Peters <tim.peters@gmail.com>
parents:
22795
diff
changeset
|
640 * Initialize the pool header, set up the free list to |
|
f1f57bf09092
Widespread, but mostly in _PyMalloc_Malloc: optimize away all expensive
Tim Peters <tim.peters@gmail.com>
parents:
22795
diff
changeset
|
641 * contain just the second block, and return the first |
|
f1f57bf09092
Widespread, but mostly in _PyMalloc_Malloc: optimize away all expensive
Tim Peters <tim.peters@gmail.com>
parents:
22795
diff
changeset
|
642 * block. |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
643 */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
644 pool->szidx = size; |
|
22836
f1f57bf09092
Widespread, but mostly in _PyMalloc_Malloc: optimize away all expensive
Tim Peters <tim.peters@gmail.com>
parents:
22795
diff
changeset
|
645 size = INDEX2SIZE(size); |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
646 bp = (block *)pool + POOL_OVERHEAD; |
|
22836
f1f57bf09092
Widespread, but mostly in _PyMalloc_Malloc: optimize away all expensive
Tim Peters <tim.peters@gmail.com>
parents:
22795
diff
changeset
|
647 pool->nextoffset = POOL_OVERHEAD + (size << 1); |
|
f1f57bf09092
Widespread, but mostly in _PyMalloc_Malloc: optimize away all expensive
Tim Peters <tim.peters@gmail.com>
parents:
22795
diff
changeset
|
648 pool->maxnextoffset = POOL_SIZE - size; |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
649 pool->freeblock = bp + size; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
650 *(block **)(pool->freeblock) = NULL; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
651 UNLOCK(); |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
652 return (void *)bp; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
653 } |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
654 /* |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
655 * Allocate new pool |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
656 */ |
|
22686
f8bd930644aa
Now that we're no longer linking arenas together, there's no need to
Tim Peters <tim.peters@gmail.com>
parents:
22685
diff
changeset
|
657 if (nfreepools) { |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
658 commit_pool: |
|
22686
f8bd930644aa
Now that we're no longer linking arenas together, there's no need to
Tim Peters <tim.peters@gmail.com>
parents:
22685
diff
changeset
|
659 --nfreepools; |
|
f8bd930644aa
Now that we're no longer linking arenas together, there's no need to
Tim Peters <tim.peters@gmail.com>
parents:
22685
diff
changeset
|
660 pool = (poolp)arenabase; |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
661 arenabase += POOL_SIZE; |
| 22684 | 662 pool->arenaindex = narenas - 1; |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
663 pool->szidx = DUMMY_SIZE_IDX; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
664 goto init_pool; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
665 } |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
666 /* |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
667 * Allocate new arena |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
668 */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
669 #ifdef WITH_MEMORY_LIMITS |
| 22684 | 670 if (!(narenas < MAX_ARENAS)) { |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
671 UNLOCK(); |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
672 goto redirect; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
673 } |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
674 #endif |
| 22684 | 675 bp = new_arena(); |
| 676 if (bp != NULL) | |
| 677 goto commit_pool; | |
| 678 UNLOCK(); | |
| 679 goto redirect; | |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
680 } |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
681 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
682 /* The small block allocator ends here. */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
683 |
| 22684 | 684 redirect: |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
685 /* |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
686 * Redirect the original request to the underlying (libc) allocator. |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
687 * We jump here on bigger requests, on error in the code above (as a |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
688 * last chance to serve the request) or when the max memory limit |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
689 * has been reached. |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
690 */ |
|
23158
4ab21e354403
PyObject_Malloc: make a tiny bit faster for platforms where malloc(0)
Tim Peters <tim.peters@gmail.com>
parents:
23157
diff
changeset
|
691 if (nbytes == 0) |
|
4ab21e354403
PyObject_Malloc: make a tiny bit faster for platforms where malloc(0)
Tim Peters <tim.peters@gmail.com>
parents:
23157
diff
changeset
|
692 nbytes = 1; |
|
4ab21e354403
PyObject_Malloc: make a tiny bit faster for platforms where malloc(0)
Tim Peters <tim.peters@gmail.com>
parents:
23157
diff
changeset
|
693 return (void *)malloc(nbytes); |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
694 } |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
695 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
696 /* free */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
697 |
|
22983
1c26a3106653
Move PyObject_Malloc and PyObject_Free here from object.c. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22948
diff
changeset
|
698 #undef PyObject_Free |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
699 void |
|
22983
1c26a3106653
Move PyObject_Malloc and PyObject_Free here from object.c. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22948
diff
changeset
|
700 PyObject_Free(void *p) |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
701 { |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
702 poolp pool; |
|
22698
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
703 block *lastfree; |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
704 poolp next, prev; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
705 uint size; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
706 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
707 if (p == NULL) /* free(NULL) has no effect */ |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
708 return; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
709 |
| 22684 | 710 pool = POOL_ADDR(p); |
| 711 if (ADDRESS_IN_RANGE(p, pool->arenaindex)) { | |
| 712 /* We allocated this address. */ | |
|
22697
6bb4386b1111
Added a long-overdue comment block giving an overview of pool operations
Tim Peters <tim.peters@gmail.com>
parents:
22692
diff
changeset
|
713 LOCK(); |
| 22684 | 714 /* |
|
22698
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
715 * Link p to the start of the pool's freeblock list. Since |
|
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
716 * the pool had at least the p block outstanding, the pool |
|
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
717 * wasn't empty (so it's already in a usedpools[] list, or |
|
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
718 * was full and is in no list -- it's not in the freeblocks |
|
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
719 * list in any case). |
| 22684 | 720 */ |
|
22701
cf1a05c86595
Add one more assert that indirectly interlocking conditions are consistent
Tim Peters <tim.peters@gmail.com>
parents:
22700
diff
changeset
|
721 assert(pool->ref.count > 0); /* else it was empty */ |
|
22698
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
722 *(block **)p = lastfree = pool->freeblock; |
|
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
723 pool->freeblock = (block *)p; |
|
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
724 if (lastfree) { |
| 22684 | 725 /* |
|
22698
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
726 * freeblock wasn't NULL, so the pool wasn't full, |
|
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
727 * and the pool is in a usedpools[] list. |
| 22684 | 728 */ |
|
22698
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
729 if (--pool->ref.count != 0) { |
|
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
730 /* pool isn't empty: leave it in usedpools */ |
|
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
731 UNLOCK(); |
|
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
732 return; |
|
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
733 } |
|
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
734 /* |
|
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
735 * Pool is now empty: unlink from usedpools, and |
|
22699
35f58c297899
Fixed a typo in a new comment.
Tim Peters <tim.peters@gmail.com>
parents:
22698
diff
changeset
|
736 * link to the front of freepools. This ensures that |
|
22698
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
737 * previously freed pools will be allocated later |
|
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
738 * (being not referenced, they are perhaps paged out). |
|
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
739 */ |
|
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
740 next = pool->nextpool; |
|
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
741 prev = pool->prevpool; |
|
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
742 next->prevpool = prev; |
|
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
743 prev->nextpool = next; |
|
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
744 /* Link to freepools. This is a singly-linked list, |
|
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
745 * and pool->prevpool isn't used there. |
|
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
746 */ |
|
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
747 pool->nextpool = freepools; |
|
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
748 freepools = pool; |
| 22684 | 749 UNLOCK(); |
| 750 return; | |
| 751 } | |
| 752 /* | |
|
22698
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
753 * Pool was full, so doesn't currently live in any list: |
|
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
754 * link it to the front of the appropriate usedpools[] list. |
|
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
755 * This mimics LRU pool usage for new allocations and |
|
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
756 * targets optimal filling when several pools contain |
|
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
757 * blocks of the same size class. |
| 22684 | 758 */ |
|
22698
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
759 --pool->ref.count; |
|
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
760 assert(pool->ref.count > 0); /* else the pool is empty */ |
|
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
761 size = pool->szidx; |
|
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
762 next = usedpools[size + size]; |
|
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
763 prev = next->prevpool; |
|
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
764 /* insert pool before next: prev <-> pool <-> next */ |
|
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
765 pool->nextpool = next; |
|
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
766 pool->prevpool = prev; |
|
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
767 next->prevpool = pool; |
|
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
768 prev->nextpool = pool; |
| 22684 | 769 UNLOCK(); |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
770 return; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
771 } |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
772 |
|
22698
a4a1e6f55531
_PyMalloc_Free(): As was already done for _PyMalloc_Malloc, rearranged
Tim Peters <tim.peters@gmail.com>
parents:
22697
diff
changeset
|
773 /* We didn't allocate this address. */ |
|
22794
f663ffbe9e5c
_PyMalloc_{Malloc, Realloc}: Strive to meet the doc's promises about
Tim Peters <tim.peters@gmail.com>
parents:
22743
diff
changeset
|
774 free(p); |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
775 } |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
776 |
|
22794
f663ffbe9e5c
_PyMalloc_{Malloc, Realloc}: Strive to meet the doc's promises about
Tim Peters <tim.peters@gmail.com>
parents:
22743
diff
changeset
|
777 /* realloc. If p is NULL, this acts like malloc(nbytes). Else if nbytes==0, |
|
f663ffbe9e5c
_PyMalloc_{Malloc, Realloc}: Strive to meet the doc's promises about
Tim Peters <tim.peters@gmail.com>
parents:
22743
diff
changeset
|
778 * then as the Python docs promise, we do not treat this like free(p), and |
|
f663ffbe9e5c
_PyMalloc_{Malloc, Realloc}: Strive to meet the doc's promises about
Tim Peters <tim.peters@gmail.com>
parents:
22743
diff
changeset
|
779 * return a non-NULL result. |
|
f663ffbe9e5c
_PyMalloc_{Malloc, Realloc}: Strive to meet the doc's promises about
Tim Peters <tim.peters@gmail.com>
parents:
22743
diff
changeset
|
780 */ |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
781 |
|
22983
1c26a3106653
Move PyObject_Malloc and PyObject_Free here from object.c. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22948
diff
changeset
|
782 #undef PyObject_Realloc |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
783 void * |
|
22983
1c26a3106653
Move PyObject_Malloc and PyObject_Free here from object.c. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22948
diff
changeset
|
784 PyObject_Realloc(void *p, size_t nbytes) |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
785 { |
|
22794
f663ffbe9e5c
_PyMalloc_{Malloc, Realloc}: Strive to meet the doc's promises about
Tim Peters <tim.peters@gmail.com>
parents:
22743
diff
changeset
|
786 void *bp; |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
787 poolp pool; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
788 uint size; |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
789 |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
790 if (p == NULL) |
|
22983
1c26a3106653
Move PyObject_Malloc and PyObject_Free here from object.c. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22948
diff
changeset
|
791 return PyObject_Malloc(nbytes); |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
792 |
| 22684 | 793 pool = POOL_ADDR(p); |
| 794 if (ADDRESS_IN_RANGE(p, pool->arenaindex)) { | |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
795 /* We're in charge of this block */ |
|
22836
f1f57bf09092
Widespread, but mostly in _PyMalloc_Malloc: optimize away all expensive
Tim Peters <tim.peters@gmail.com>
parents:
22795
diff
changeset
|
796 size = INDEX2SIZE(pool->szidx); |
|
23363
36840a989722
PyObject_Realloc(): If a small block is shrinking, bite the expense of
Tim Peters <tim.peters@gmail.com>
parents:
23298
diff
changeset
|
797 if (nbytes <= size) { |
|
36840a989722
PyObject_Realloc(): If a small block is shrinking, bite the expense of
Tim Peters <tim.peters@gmail.com>
parents:
23298
diff
changeset
|
798 /* The block is staying the same or shrinking. If |
|
36840a989722
PyObject_Realloc(): If a small block is shrinking, bite the expense of
Tim Peters <tim.peters@gmail.com>
parents:
23298
diff
changeset
|
799 * it's shrinking, there's a tradeoff: it costs |
|
36840a989722
PyObject_Realloc(): If a small block is shrinking, bite the expense of
Tim Peters <tim.peters@gmail.com>
parents:
23298
diff
changeset
|
800 * cycles to copy the block to a smaller size class, |
|
36840a989722
PyObject_Realloc(): If a small block is shrinking, bite the expense of
Tim Peters <tim.peters@gmail.com>
parents:
23298
diff
changeset
|
801 * but it wastes memory not to copy it. The |
|
36840a989722
PyObject_Realloc(): If a small block is shrinking, bite the expense of
Tim Peters <tim.peters@gmail.com>
parents:
23298
diff
changeset
|
802 * compromise here is to copy on shrink only if at |
|
36840a989722
PyObject_Realloc(): If a small block is shrinking, bite the expense of
Tim Peters <tim.peters@gmail.com>
parents:
23298
diff
changeset
|
803 * least 25% of size can be shaved off. |
|
36840a989722
PyObject_Realloc(): If a small block is shrinking, bite the expense of
Tim Peters <tim.peters@gmail.com>
parents:
23298
diff
changeset
|
804 */ |
|
36840a989722
PyObject_Realloc(): If a small block is shrinking, bite the expense of
Tim Peters <tim.peters@gmail.com>
parents:
23298
diff
changeset
|
805 if (4 * nbytes > 3 * size) { |
|
36840a989722
PyObject_Realloc(): If a small block is shrinking, bite the expense of
Tim Peters <tim.peters@gmail.com>
parents:
23298
diff
changeset
|
806 /* It's the same, |
|
36840a989722
PyObject_Realloc(): If a small block is shrinking, bite the expense of
Tim Peters <tim.peters@gmail.com>
parents:
23298
diff
changeset
|
807 * or shrinking and new/old > 3/4. |
|
36840a989722
PyObject_Realloc(): If a small block is shrinking, bite the expense of
Tim Peters <tim.peters@gmail.com>
parents:
23298
diff
changeset
|
808 */ |
|
36840a989722
PyObject_Realloc(): If a small block is shrinking, bite the expense of
Tim Peters <tim.peters@gmail.com>
parents:
23298
diff
changeset
|
809 return p; |
|
36840a989722
PyObject_Realloc(): If a small block is shrinking, bite the expense of
Tim Peters <tim.peters@gmail.com>
parents:
23298
diff
changeset
|
810 } |
|
36840a989722
PyObject_Realloc(): If a small block is shrinking, bite the expense of
Tim Peters <tim.peters@gmail.com>
parents:
23298
diff
changeset
|
811 size = nbytes; |
|
36840a989722
PyObject_Realloc(): If a small block is shrinking, bite the expense of
Tim Peters <tim.peters@gmail.com>
parents:
23298
diff
changeset
|
812 } |
|
22983
1c26a3106653
Move PyObject_Malloc and PyObject_Free here from object.c. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22948
diff
changeset
|
813 bp = PyObject_Malloc(nbytes); |
|
22794
f663ffbe9e5c
_PyMalloc_{Malloc, Realloc}: Strive to meet the doc's promises about
Tim Peters <tim.peters@gmail.com>
parents:
22743
diff
changeset
|
814 if (bp != NULL) { |
|
f663ffbe9e5c
_PyMalloc_{Malloc, Realloc}: Strive to meet the doc's promises about
Tim Peters <tim.peters@gmail.com>
parents:
22743
diff
changeset
|
815 memcpy(bp, p, size); |
|
22983
1c26a3106653
Move PyObject_Malloc and PyObject_Free here from object.c. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22948
diff
changeset
|
816 PyObject_Free(p); |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
817 } |
|
22794
f663ffbe9e5c
_PyMalloc_{Malloc, Realloc}: Strive to meet the doc's promises about
Tim Peters <tim.peters@gmail.com>
parents:
22743
diff
changeset
|
818 return bp; |
|
f663ffbe9e5c
_PyMalloc_{Malloc, Realloc}: Strive to meet the doc's promises about
Tim Peters <tim.peters@gmail.com>
parents:
22743
diff
changeset
|
819 } |
|
f663ffbe9e5c
_PyMalloc_{Malloc, Realloc}: Strive to meet the doc's promises about
Tim Peters <tim.peters@gmail.com>
parents:
22743
diff
changeset
|
820 /* We're not managing this block. */ |
|
f663ffbe9e5c
_PyMalloc_{Malloc, Realloc}: Strive to meet the doc's promises about
Tim Peters <tim.peters@gmail.com>
parents:
22743
diff
changeset
|
821 if (nbytes <= SMALL_REQUEST_THRESHOLD) { |
|
23158
4ab21e354403
PyObject_Malloc: make a tiny bit faster for platforms where malloc(0)
Tim Peters <tim.peters@gmail.com>
parents:
23157
diff
changeset
|
822 /* Take over this block -- ask for at least one byte so |
|
4ab21e354403
PyObject_Malloc: make a tiny bit faster for platforms where malloc(0)
Tim Peters <tim.peters@gmail.com>
parents:
23157
diff
changeset
|
823 * we really do take it over (PyObject_Malloc(0) goes to |
|
4ab21e354403
PyObject_Malloc: make a tiny bit faster for platforms where malloc(0)
Tim Peters <tim.peters@gmail.com>
parents:
23157
diff
changeset
|
824 * the system malloc). |
|
4ab21e354403
PyObject_Malloc: make a tiny bit faster for platforms where malloc(0)
Tim Peters <tim.peters@gmail.com>
parents:
23157
diff
changeset
|
825 */ |
|
22983
1c26a3106653
Move PyObject_Malloc and PyObject_Free here from object.c. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22948
diff
changeset
|
826 bp = PyObject_Malloc(nbytes ? nbytes : 1); |
|
22794
f663ffbe9e5c
_PyMalloc_{Malloc, Realloc}: Strive to meet the doc's promises about
Tim Peters <tim.peters@gmail.com>
parents:
22743
diff
changeset
|
827 if (bp != NULL) { |
|
f663ffbe9e5c
_PyMalloc_{Malloc, Realloc}: Strive to meet the doc's promises about
Tim Peters <tim.peters@gmail.com>
parents:
22743
diff
changeset
|
828 memcpy(bp, p, nbytes); |
|
f663ffbe9e5c
_PyMalloc_{Malloc, Realloc}: Strive to meet the doc's promises about
Tim Peters <tim.peters@gmail.com>
parents:
22743
diff
changeset
|
829 free(p); |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
830 } |
|
22794
f663ffbe9e5c
_PyMalloc_{Malloc, Realloc}: Strive to meet the doc's promises about
Tim Peters <tim.peters@gmail.com>
parents:
22743
diff
changeset
|
831 else if (nbytes == 0) { |
|
f663ffbe9e5c
_PyMalloc_{Malloc, Realloc}: Strive to meet the doc's promises about
Tim Peters <tim.peters@gmail.com>
parents:
22743
diff
changeset
|
832 /* Meet the doc's promise that nbytes==0 will |
|
f663ffbe9e5c
_PyMalloc_{Malloc, Realloc}: Strive to meet the doc's promises about
Tim Peters <tim.peters@gmail.com>
parents:
22743
diff
changeset
|
833 * never return a NULL pointer when p isn't NULL. |
|
f663ffbe9e5c
_PyMalloc_{Malloc, Realloc}: Strive to meet the doc's promises about
Tim Peters <tim.peters@gmail.com>
parents:
22743
diff
changeset
|
834 */ |
|
f663ffbe9e5c
_PyMalloc_{Malloc, Realloc}: Strive to meet the doc's promises about
Tim Peters <tim.peters@gmail.com>
parents:
22743
diff
changeset
|
835 bp = p; |
|
f663ffbe9e5c
_PyMalloc_{Malloc, Realloc}: Strive to meet the doc's promises about
Tim Peters <tim.peters@gmail.com>
parents:
22743
diff
changeset
|
836 } |
|
f663ffbe9e5c
_PyMalloc_{Malloc, Realloc}: Strive to meet the doc's promises about
Tim Peters <tim.peters@gmail.com>
parents:
22743
diff
changeset
|
837 |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
838 } |
| 22684 | 839 else { |
|
22794
f663ffbe9e5c
_PyMalloc_{Malloc, Realloc}: Strive to meet the doc's promises about
Tim Peters <tim.peters@gmail.com>
parents:
22743
diff
changeset
|
840 assert(nbytes != 0); |
|
f663ffbe9e5c
_PyMalloc_{Malloc, Realloc}: Strive to meet the doc's promises about
Tim Peters <tim.peters@gmail.com>
parents:
22743
diff
changeset
|
841 bp = realloc(p, nbytes); |
| 22684 | 842 } |
|
22794
f663ffbe9e5c
_PyMalloc_{Malloc, Realloc}: Strive to meet the doc's promises about
Tim Peters <tim.peters@gmail.com>
parents:
22743
diff
changeset
|
843 return bp; |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
844 } |
|
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
845 |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
846 #else /* ! WITH_PYMALLOC */ |
|
16782
5864a9c58c81
Add Vladimir Marangozov's object allocator. It is disabled by default. This
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
diff
changeset
|
847 |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
848 /*==========================================================================*/ |
|
22983
1c26a3106653
Move PyObject_Malloc and PyObject_Free here from object.c. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22948
diff
changeset
|
849 /* pymalloc not enabled: Redirect the entry points to malloc. These will |
|
1c26a3106653
Move PyObject_Malloc and PyObject_Free here from object.c. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22948
diff
changeset
|
850 * only be used by extensions that are compiled with pymalloc enabled. */ |
|
22484
ffcb2fd2947e
Minor code cleanup -- no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
22479
diff
changeset
|
851 |
|
22470
0e4758ccfe2b
Just whitespace fiddling.
Tim Peters <tim.peters@gmail.com>
parents:
22469
diff
changeset
|
852 void * |
|
22983
1c26a3106653
Move PyObject_Malloc and PyObject_Free here from object.c. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22948
diff
changeset
|
853 PyObject_Malloc(size_t n) |
|
22469
8d0061493c57
Build obmalloc.c directly instead of #include'ing from object.c.
Tim Peters <tim.peters@gmail.com>
parents:
22465
diff
changeset
|
854 { |
|
8d0061493c57
Build obmalloc.c directly instead of #include'ing from object.c.
Tim Peters <tim.peters@gmail.com>
parents:
22465
diff
changeset
|
855 return PyMem_MALLOC(n); |
|
8d0061493c57
Build obmalloc.c directly instead of #include'ing from object.c.
Tim Peters <tim.peters@gmail.com>
parents:
22465
diff
changeset
|
856 } |
|
8d0061493c57
Build obmalloc.c directly instead of #include'ing from object.c.
Tim Peters <tim.peters@gmail.com>
parents:
22465
diff
changeset
|
857 |
|
22470
0e4758ccfe2b
Just whitespace fiddling.
Tim Peters <tim.peters@gmail.com>
parents:
22469
diff
changeset
|
858 void * |
|
22983
1c26a3106653
Move PyObject_Malloc and PyObject_Free here from object.c. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22948
diff
changeset
|
859 PyObject_Realloc(void *p, size_t n) |
|
22469
8d0061493c57
Build obmalloc.c directly instead of #include'ing from object.c.
Tim Peters <tim.peters@gmail.com>
parents:
22465
diff
changeset
|
860 { |
|
8d0061493c57
Build obmalloc.c directly instead of #include'ing from object.c.
Tim Peters <tim.peters@gmail.com>
parents:
22465
diff
changeset
|
861 return PyMem_REALLOC(p, n); |
|
8d0061493c57
Build obmalloc.c directly instead of #include'ing from object.c.
Tim Peters <tim.peters@gmail.com>
parents:
22465
diff
changeset
|
862 } |
|
8d0061493c57
Build obmalloc.c directly instead of #include'ing from object.c.
Tim Peters <tim.peters@gmail.com>
parents:
22465
diff
changeset
|
863 |
|
8d0061493c57
Build obmalloc.c directly instead of #include'ing from object.c.
Tim Peters <tim.peters@gmail.com>
parents:
22465
diff
changeset
|
864 void |
|
22983
1c26a3106653
Move PyObject_Malloc and PyObject_Free here from object.c. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22948
diff
changeset
|
865 PyObject_Free(void *p) |
|
22469
8d0061493c57
Build obmalloc.c directly instead of #include'ing from object.c.
Tim Peters <tim.peters@gmail.com>
parents:
22465
diff
changeset
|
866 { |
|
8d0061493c57
Build obmalloc.c directly instead of #include'ing from object.c.
Tim Peters <tim.peters@gmail.com>
parents:
22465
diff
changeset
|
867 PyMem_FREE(p); |
|
8d0061493c57
Build obmalloc.c directly instead of #include'ing from object.c.
Tim Peters <tim.peters@gmail.com>
parents:
22465
diff
changeset
|
868 } |
|
8d0061493c57
Build obmalloc.c directly instead of #include'ing from object.c.
Tim Peters <tim.peters@gmail.com>
parents:
22465
diff
changeset
|
869 #endif /* WITH_PYMALLOC */ |
|
8d0061493c57
Build obmalloc.c directly instead of #include'ing from object.c.
Tim Peters <tim.peters@gmail.com>
parents:
22465
diff
changeset
|
870 |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
871 #ifdef PYMALLOC_DEBUG |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
872 /*==========================================================================*/ |
|
22484
ffcb2fd2947e
Minor code cleanup -- no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
22479
diff
changeset
|
873 /* A x-platform debugging allocator. This doesn't manage memory directly, |
|
ffcb2fd2947e
Minor code cleanup -- no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
22479
diff
changeset
|
874 * it wraps a real allocator, adding extra debugging info to the memory blocks. |
|
ffcb2fd2947e
Minor code cleanup -- no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
22479
diff
changeset
|
875 */ |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
876 |
|
22986
298a7c51d2c0
PYMALLOC_{CLEAN, DEAD, FORBIDDEN}BYTE symbols: remove the PYMALLOC_
Tim Peters <tim.peters@gmail.com>
parents:
22983
diff
changeset
|
877 /* Special bytes broadcast into debug memory blocks at appropriate times. |
|
298a7c51d2c0
PYMALLOC_{CLEAN, DEAD, FORBIDDEN}BYTE symbols: remove the PYMALLOC_
Tim Peters <tim.peters@gmail.com>
parents:
22983
diff
changeset
|
878 * Strings of these are unlikely to be valid addresses, floats, ints or |
|
298a7c51d2c0
PYMALLOC_{CLEAN, DEAD, FORBIDDEN}BYTE symbols: remove the PYMALLOC_
Tim Peters <tim.peters@gmail.com>
parents:
22983
diff
changeset
|
879 * 7-bit ASCII. |
|
298a7c51d2c0
PYMALLOC_{CLEAN, DEAD, FORBIDDEN}BYTE symbols: remove the PYMALLOC_
Tim Peters <tim.peters@gmail.com>
parents:
22983
diff
changeset
|
880 */ |
|
298a7c51d2c0
PYMALLOC_{CLEAN, DEAD, FORBIDDEN}BYTE symbols: remove the PYMALLOC_
Tim Peters <tim.peters@gmail.com>
parents:
22983
diff
changeset
|
881 #undef CLEANBYTE |
|
298a7c51d2c0
PYMALLOC_{CLEAN, DEAD, FORBIDDEN}BYTE symbols: remove the PYMALLOC_
Tim Peters <tim.peters@gmail.com>
parents:
22983
diff
changeset
|
882 #undef DEADBYTE |
|
298a7c51d2c0
PYMALLOC_{CLEAN, DEAD, FORBIDDEN}BYTE symbols: remove the PYMALLOC_
Tim Peters <tim.peters@gmail.com>
parents:
22983
diff
changeset
|
883 #undef FORBIDDENBYTE |
|
298a7c51d2c0
PYMALLOC_{CLEAN, DEAD, FORBIDDEN}BYTE symbols: remove the PYMALLOC_
Tim Peters <tim.peters@gmail.com>
parents:
22983
diff
changeset
|
884 #define CLEANBYTE 0xCB /* clean (newly allocated) memory */ |
|
24177
a038abd08e4a
Documented PYMALLOC_DEBUG. This completes primary coverage of all the
Tim Peters <tim.peters@gmail.com>
parents:
23363
diff
changeset
|
885 #define DEADBYTE 0xDB /* dead (newly freed) memory */ |
|
22986
298a7c51d2c0
PYMALLOC_{CLEAN, DEAD, FORBIDDEN}BYTE symbols: remove the PYMALLOC_
Tim Peters <tim.peters@gmail.com>
parents:
22983
diff
changeset
|
886 #define FORBIDDENBYTE 0xFB /* untouchable bytes at each end of a block */ |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
887 |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
888 static ulong serialno = 0; /* incremented on each debug {m,re}alloc */ |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
889 |
|
22487
f02cdb2bc17a
_PyMalloc_DebugRealloc(): simplify decl of "fresh".
Tim Peters <tim.peters@gmail.com>
parents:
22484
diff
changeset
|
890 /* serialno is always incremented via calling this routine. The point is |
|
f02cdb2bc17a
_PyMalloc_DebugRealloc(): simplify decl of "fresh".
Tim Peters <tim.peters@gmail.com>
parents:
22484
diff
changeset
|
891 to supply a single place to set a breakpoint. |
|
f02cdb2bc17a
_PyMalloc_DebugRealloc(): simplify decl of "fresh".
Tim Peters <tim.peters@gmail.com>
parents:
22484
diff
changeset
|
892 */ |
|
f02cdb2bc17a
_PyMalloc_DebugRealloc(): simplify decl of "fresh".
Tim Peters <tim.peters@gmail.com>
parents:
22484
diff
changeset
|
893 static void |
|
22631
7870fac049f7
Add missing "void" to function.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22614
diff
changeset
|
894 bumpserialno(void) |
|
22487
f02cdb2bc17a
_PyMalloc_DebugRealloc(): simplify decl of "fresh".
Tim Peters <tim.peters@gmail.com>
parents:
22484
diff
changeset
|
895 { |
|
f02cdb2bc17a
_PyMalloc_DebugRealloc(): simplify decl of "fresh".
Tim Peters <tim.peters@gmail.com>
parents:
22484
diff
changeset
|
896 ++serialno; |
|
f02cdb2bc17a
_PyMalloc_DebugRealloc(): simplify decl of "fresh".
Tim Peters <tim.peters@gmail.com>
parents:
22484
diff
changeset
|
897 } |
|
f02cdb2bc17a
_PyMalloc_DebugRealloc(): simplify decl of "fresh".
Tim Peters <tim.peters@gmail.com>
parents:
22484
diff
changeset
|
898 |
|
f02cdb2bc17a
_PyMalloc_DebugRealloc(): simplify decl of "fresh".
Tim Peters <tim.peters@gmail.com>
parents:
22484
diff
changeset
|
899 |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
900 /* Read 4 bytes at p as a big-endian ulong. */ |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
901 static ulong |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
902 read4(const void *p) |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
903 { |
|
22484
ffcb2fd2947e
Minor code cleanup -- no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
22479
diff
changeset
|
904 const uchar *q = (const uchar *)p; |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
905 return ((ulong)q[0] << 24) | |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
906 ((ulong)q[1] << 16) | |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
907 ((ulong)q[2] << 8) | |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
908 (ulong)q[3]; |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
909 } |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
910 |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
911 /* Write the 4 least-significant bytes of n as a big-endian unsigned int, |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
912 MSB at address p, LSB at p+3. */ |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
913 static void |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
914 write4(void *p, ulong n) |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
915 { |
|
22484
ffcb2fd2947e
Minor code cleanup -- no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
22479
diff
changeset
|
916 uchar *q = (uchar *)p; |
|
ffcb2fd2947e
Minor code cleanup -- no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
22479
diff
changeset
|
917 q[0] = (uchar)((n >> 24) & 0xff); |
|
ffcb2fd2947e
Minor code cleanup -- no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
22479
diff
changeset
|
918 q[1] = (uchar)((n >> 16) & 0xff); |
|
ffcb2fd2947e
Minor code cleanup -- no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
22479
diff
changeset
|
919 q[2] = (uchar)((n >> 8) & 0xff); |
|
ffcb2fd2947e
Minor code cleanup -- no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
22479
diff
changeset
|
920 q[3] = (uchar)( n & 0xff); |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
921 } |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
922 |
|
23159
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
923 #ifdef Py_DEBUG |
|
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
924 /* Is target in the list? The list is traversed via the nextpool pointers. |
|
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
925 * The list may be NULL-terminated, or circular. Return 1 if target is in |
|
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
926 * list, else 0. |
|
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
927 */ |
|
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
928 static int |
|
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
929 pool_is_in_list(const poolp target, poolp list) |
|
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
930 { |
|
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
931 poolp origlist = list; |
|
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
932 assert(target != NULL); |
|
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
933 if (list == NULL) |
|
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
934 return 0; |
|
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
935 do { |
|
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
936 if (target == list) |
|
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
937 return 1; |
|
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
938 list = list->nextpool; |
|
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
939 } while (list != NULL && list != origlist); |
|
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
940 return 0; |
|
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
941 } |
|
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
942 |
|
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
943 #else |
|
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
944 #define pool_is_in_list(X, Y) 1 |
|
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
945 |
|
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
946 #endif /* Py_DEBUG */ |
|
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
947 |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
948 /* The debug malloc asks for 16 extra bytes and fills them with useful stuff, |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
949 here calling the underlying malloc's result p: |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
950 |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
951 p[0:4] |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
952 Number of bytes originally asked for. 4-byte unsigned integer, |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
953 big-endian (easier to read in a memory dump). |
|
22614
f294fdd18b5b
PYMALLOC_DEBUG routines: The "check API family" gimmick was going nowhere
Tim Peters <tim.peters@gmail.com>
parents:
22487
diff
changeset
|
954 p[4:8] |
|
22986
298a7c51d2c0
PYMALLOC_{CLEAN, DEAD, FORBIDDEN}BYTE symbols: remove the PYMALLOC_
Tim Peters <tim.peters@gmail.com>
parents:
22983
diff
changeset
|
955 Copies of FORBIDDENBYTE. Used to catch under- writes and reads. |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
956 p[8:8+n] |
|
22986
298a7c51d2c0
PYMALLOC_{CLEAN, DEAD, FORBIDDEN}BYTE symbols: remove the PYMALLOC_
Tim Peters <tim.peters@gmail.com>
parents:
22983
diff
changeset
|
957 The requested memory, filled with copies of CLEANBYTE. |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
958 Used to catch reference to uninitialized memory. |
|
22983
1c26a3106653
Move PyObject_Malloc and PyObject_Free here from object.c. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22948
diff
changeset
|
959 &p[8] is returned. Note that this is 8-byte aligned if pymalloc |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
960 handled the request itself. |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
961 p[8+n:8+n+4] |
|
22986
298a7c51d2c0
PYMALLOC_{CLEAN, DEAD, FORBIDDEN}BYTE symbols: remove the PYMALLOC_
Tim Peters <tim.peters@gmail.com>
parents:
22983
diff
changeset
|
962 Copies of FORBIDDENBYTE. Used to catch over- writes and reads. |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
963 p[8+n+4:8+n+8] |
|
22983
1c26a3106653
Move PyObject_Malloc and PyObject_Free here from object.c. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22948
diff
changeset
|
964 A serial number, incremented by 1 on each call to _PyObject_DebugMalloc |
|
1c26a3106653
Move PyObject_Malloc and PyObject_Free here from object.c. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22948
diff
changeset
|
965 and _PyObject_DebugRealloc. |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
966 4-byte unsigned integer, big-endian. |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
967 If "bad memory" is detected later, the serial number gives an |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
968 excellent way to set a breakpoint on the next run, to capture the |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
969 instant at which this block was passed out. |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
970 */ |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
971 |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
972 void * |
|
22983
1c26a3106653
Move PyObject_Malloc and PyObject_Free here from object.c. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22948
diff
changeset
|
973 _PyObject_DebugMalloc(size_t nbytes) |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
974 { |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
975 uchar *p; /* base address of malloc'ed block */ |
|
22484
ffcb2fd2947e
Minor code cleanup -- no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
22479
diff
changeset
|
976 uchar *tail; /* p + 8 + nbytes == pointer to tail pad bytes */ |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
977 size_t total; /* nbytes + 16 */ |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
978 |
|
22487
f02cdb2bc17a
_PyMalloc_DebugRealloc(): simplify decl of "fresh".
Tim Peters <tim.peters@gmail.com>
parents:
22484
diff
changeset
|
979 bumpserialno(); |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
980 total = nbytes + 16; |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
981 if (total < nbytes || (total >> 31) > 1) { |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
982 /* overflow, or we can't represent it in 4 bytes */ |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
983 /* Obscure: can't do (total >> 32) != 0 instead, because |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
984 C doesn't define what happens for a right-shift of 32 |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
985 when size_t is a 32-bit type. At least C guarantees |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
986 size_t is an unsigned type. */ |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
987 return NULL; |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
988 } |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
989 |
|
23009
8be6238748c4
Small anal correctness tweaks:
Tim Peters <tim.peters@gmail.com>
parents:
22988
diff
changeset
|
990 p = (uchar *)PyObject_Malloc(total); |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
991 if (p == NULL) |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
992 return NULL; |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
993 |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
994 write4(p, nbytes); |
|
22986
298a7c51d2c0
PYMALLOC_{CLEAN, DEAD, FORBIDDEN}BYTE symbols: remove the PYMALLOC_
Tim Peters <tim.peters@gmail.com>
parents:
22983
diff
changeset
|
995 p[4] = p[5] = p[6] = p[7] = FORBIDDENBYTE; |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
996 |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
997 if (nbytes > 0) |
|
22986
298a7c51d2c0
PYMALLOC_{CLEAN, DEAD, FORBIDDEN}BYTE symbols: remove the PYMALLOC_
Tim Peters <tim.peters@gmail.com>
parents:
22983
diff
changeset
|
998 memset(p+8, CLEANBYTE, nbytes); |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
999 |
|
22484
ffcb2fd2947e
Minor code cleanup -- no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
22479
diff
changeset
|
1000 tail = p + 8 + nbytes; |
|
22986
298a7c51d2c0
PYMALLOC_{CLEAN, DEAD, FORBIDDEN}BYTE symbols: remove the PYMALLOC_
Tim Peters <tim.peters@gmail.com>
parents:
22983
diff
changeset
|
1001 tail[0] = tail[1] = tail[2] = tail[3] = FORBIDDENBYTE; |
|
22484
ffcb2fd2947e
Minor code cleanup -- no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
22479
diff
changeset
|
1002 write4(tail + 4, serialno); |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1003 |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1004 return p+8; |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1005 } |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1006 |
|
22484
ffcb2fd2947e
Minor code cleanup -- no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
22479
diff
changeset
|
1007 /* The debug free first checks the 8 bytes on each end for sanity (in |
|
22986
298a7c51d2c0
PYMALLOC_{CLEAN, DEAD, FORBIDDEN}BYTE symbols: remove the PYMALLOC_
Tim Peters <tim.peters@gmail.com>
parents:
22983
diff
changeset
|
1008 particular, that the FORBIDDENBYTEs are still intact). |
|
298a7c51d2c0
PYMALLOC_{CLEAN, DEAD, FORBIDDEN}BYTE symbols: remove the PYMALLOC_
Tim Peters <tim.peters@gmail.com>
parents:
22983
diff
changeset
|
1009 Then fills the original bytes with DEADBYTE. |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1010 Then calls the underlying free. |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1011 */ |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1012 void |
|
22983
1c26a3106653
Move PyObject_Malloc and PyObject_Free here from object.c. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22948
diff
changeset
|
1013 _PyObject_DebugFree(void *p) |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1014 { |
|
22484
ffcb2fd2947e
Minor code cleanup -- no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
22479
diff
changeset
|
1015 uchar *q = (uchar *)p; |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1016 size_t nbytes; |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1017 |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1018 if (p == NULL) |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1019 return; |
|
22983
1c26a3106653
Move PyObject_Malloc and PyObject_Free here from object.c. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22948
diff
changeset
|
1020 _PyObject_DebugCheckAddress(p); |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1021 nbytes = read4(q-8); |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1022 if (nbytes > 0) |
|
22986
298a7c51d2c0
PYMALLOC_{CLEAN, DEAD, FORBIDDEN}BYTE symbols: remove the PYMALLOC_
Tim Peters <tim.peters@gmail.com>
parents:
22983
diff
changeset
|
1023 memset(q, DEADBYTE, nbytes); |
|
22983
1c26a3106653
Move PyObject_Malloc and PyObject_Free here from object.c. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22948
diff
changeset
|
1024 PyObject_Free(q-8); |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1025 } |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1026 |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1027 void * |
|
22983
1c26a3106653
Move PyObject_Malloc and PyObject_Free here from object.c. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22948
diff
changeset
|
1028 _PyObject_DebugRealloc(void *p, size_t nbytes) |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1029 { |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1030 uchar *q = (uchar *)p; |
|
22988
be54465a39c4
_PyObject_DebugRealloc(): rewritten to let the underlying realloc do
Tim Peters <tim.peters@gmail.com>
parents:
22987
diff
changeset
|
1031 uchar *tail; |
|
be54465a39c4
_PyObject_DebugRealloc(): rewritten to let the underlying realloc do
Tim Peters <tim.peters@gmail.com>
parents:
22987
diff
changeset
|
1032 size_t total; /* nbytes + 16 */ |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1033 size_t original_nbytes; |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1034 |
|
22614
f294fdd18b5b
PYMALLOC_DEBUG routines: The "check API family" gimmick was going nowhere
Tim Peters <tim.peters@gmail.com>
parents:
22487
diff
changeset
|
1035 if (p == NULL) |
|
22983
1c26a3106653
Move PyObject_Malloc and PyObject_Free here from object.c. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22948
diff
changeset
|
1036 return _PyObject_DebugMalloc(nbytes); |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1037 |
|
22983
1c26a3106653
Move PyObject_Malloc and PyObject_Free here from object.c. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22948
diff
changeset
|
1038 _PyObject_DebugCheckAddress(p); |
|
22988
be54465a39c4
_PyObject_DebugRealloc(): rewritten to let the underlying realloc do
Tim Peters <tim.peters@gmail.com>
parents:
22987
diff
changeset
|
1039 bumpserialno(); |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1040 original_nbytes = read4(q-8); |
|
22988
be54465a39c4
_PyObject_DebugRealloc(): rewritten to let the underlying realloc do
Tim Peters <tim.peters@gmail.com>
parents:
22987
diff
changeset
|
1041 total = nbytes + 16; |
|
be54465a39c4
_PyObject_DebugRealloc(): rewritten to let the underlying realloc do
Tim Peters <tim.peters@gmail.com>
parents:
22987
diff
changeset
|
1042 if (total < nbytes || (total >> 31) > 1) { |
|
be54465a39c4
_PyObject_DebugRealloc(): rewritten to let the underlying realloc do
Tim Peters <tim.peters@gmail.com>
parents:
22987
diff
changeset
|
1043 /* overflow, or we can't represent it in 4 bytes */ |
|
be54465a39c4
_PyObject_DebugRealloc(): rewritten to let the underlying realloc do
Tim Peters <tim.peters@gmail.com>
parents:
22987
diff
changeset
|
1044 return NULL; |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1045 } |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1046 |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1047 if (nbytes < original_nbytes) { |
|
22988
be54465a39c4
_PyObject_DebugRealloc(): rewritten to let the underlying realloc do
Tim Peters <tim.peters@gmail.com>
parents:
22987
diff
changeset
|
1048 /* shrinking: mark old extra memory dead */ |
|
be54465a39c4
_PyObject_DebugRealloc(): rewritten to let the underlying realloc do
Tim Peters <tim.peters@gmail.com>
parents:
22987
diff
changeset
|
1049 memset(q + nbytes, DEADBYTE, original_nbytes - nbytes); |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1050 } |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1051 |
|
22988
be54465a39c4
_PyObject_DebugRealloc(): rewritten to let the underlying realloc do
Tim Peters <tim.peters@gmail.com>
parents:
22987
diff
changeset
|
1052 /* Resize and add decorations. */ |
|
be54465a39c4
_PyObject_DebugRealloc(): rewritten to let the underlying realloc do
Tim Peters <tim.peters@gmail.com>
parents:
22987
diff
changeset
|
1053 q = (uchar *)PyObject_Realloc(q-8, total); |
|
be54465a39c4
_PyObject_DebugRealloc(): rewritten to let the underlying realloc do
Tim Peters <tim.peters@gmail.com>
parents:
22987
diff
changeset
|
1054 if (q == NULL) |
|
be54465a39c4
_PyObject_DebugRealloc(): rewritten to let the underlying realloc do
Tim Peters <tim.peters@gmail.com>
parents:
22987
diff
changeset
|
1055 return NULL; |
|
be54465a39c4
_PyObject_DebugRealloc(): rewritten to let the underlying realloc do
Tim Peters <tim.peters@gmail.com>
parents:
22987
diff
changeset
|
1056 |
|
be54465a39c4
_PyObject_DebugRealloc(): rewritten to let the underlying realloc do
Tim Peters <tim.peters@gmail.com>
parents:
22987
diff
changeset
|
1057 write4(q, nbytes); |
|
be54465a39c4
_PyObject_DebugRealloc(): rewritten to let the underlying realloc do
Tim Peters <tim.peters@gmail.com>
parents:
22987
diff
changeset
|
1058 assert(q[4] == FORBIDDENBYTE && |
|
be54465a39c4
_PyObject_DebugRealloc(): rewritten to let the underlying realloc do
Tim Peters <tim.peters@gmail.com>
parents:
22987
diff
changeset
|
1059 q[5] == FORBIDDENBYTE && |
|
be54465a39c4
_PyObject_DebugRealloc(): rewritten to let the underlying realloc do
Tim Peters <tim.peters@gmail.com>
parents:
22987
diff
changeset
|
1060 q[6] == FORBIDDENBYTE && |
|
be54465a39c4
_PyObject_DebugRealloc(): rewritten to let the underlying realloc do
Tim Peters <tim.peters@gmail.com>
parents:
22987
diff
changeset
|
1061 q[7] == FORBIDDENBYTE); |
|
be54465a39c4
_PyObject_DebugRealloc(): rewritten to let the underlying realloc do
Tim Peters <tim.peters@gmail.com>
parents:
22987
diff
changeset
|
1062 q += 8; |
|
be54465a39c4
_PyObject_DebugRealloc(): rewritten to let the underlying realloc do
Tim Peters <tim.peters@gmail.com>
parents:
22987
diff
changeset
|
1063 tail = q + nbytes; |
|
be54465a39c4
_PyObject_DebugRealloc(): rewritten to let the underlying realloc do
Tim Peters <tim.peters@gmail.com>
parents:
22987
diff
changeset
|
1064 tail[0] = tail[1] = tail[2] = tail[3] = FORBIDDENBYTE; |
|
be54465a39c4
_PyObject_DebugRealloc(): rewritten to let the underlying realloc do
Tim Peters <tim.peters@gmail.com>
parents:
22987
diff
changeset
|
1065 write4(tail + 4, serialno); |
|
be54465a39c4
_PyObject_DebugRealloc(): rewritten to let the underlying realloc do
Tim Peters <tim.peters@gmail.com>
parents:
22987
diff
changeset
|
1066 |
|
be54465a39c4
_PyObject_DebugRealloc(): rewritten to let the underlying realloc do
Tim Peters <tim.peters@gmail.com>
parents:
22987
diff
changeset
|
1067 if (nbytes > original_nbytes) { |
|
be54465a39c4
_PyObject_DebugRealloc(): rewritten to let the underlying realloc do
Tim Peters <tim.peters@gmail.com>
parents:
22987
diff
changeset
|
1068 /* growing: mark new extra memory clean */ |
|
be54465a39c4
_PyObject_DebugRealloc(): rewritten to let the underlying realloc do
Tim Peters <tim.peters@gmail.com>
parents:
22987
diff
changeset
|
1069 memset(q + original_nbytes, CLEANBYTE, |
|
be54465a39c4
_PyObject_DebugRealloc(): rewritten to let the underlying realloc do
Tim Peters <tim.peters@gmail.com>
parents:
22987
diff
changeset
|
1070 nbytes - original_nbytes); |
|
22948
6cb52829da1a
SF bug 542181: Realloc behavior
Tim Peters <tim.peters@gmail.com>
parents:
22860
diff
changeset
|
1071 } |
|
22988
be54465a39c4
_PyObject_DebugRealloc(): rewritten to let the underlying realloc do
Tim Peters <tim.peters@gmail.com>
parents:
22987
diff
changeset
|
1072 |
|
be54465a39c4
_PyObject_DebugRealloc(): rewritten to let the underlying realloc do
Tim Peters <tim.peters@gmail.com>
parents:
22987
diff
changeset
|
1073 return q; |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1074 } |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1075 |
|
22724
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1076 /* Check the forbidden bytes on both ends of the memory allocated for p. |
|
22983
1c26a3106653
Move PyObject_Malloc and PyObject_Free here from object.c. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22948
diff
changeset
|
1077 * If anything is wrong, print info to stderr via _PyObject_DebugDumpAddress, |
|
22724
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1078 * and call Py_FatalError to kill the program. |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1079 */ |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1080 void |
|
22983
1c26a3106653
Move PyObject_Malloc and PyObject_Free here from object.c. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22948
diff
changeset
|
1081 _PyObject_DebugCheckAddress(const void *p) |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1082 { |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1083 const uchar *q = (const uchar *)p; |
|
22614
f294fdd18b5b
PYMALLOC_DEBUG routines: The "check API family" gimmick was going nowhere
Tim Peters <tim.peters@gmail.com>
parents:
22487
diff
changeset
|
1084 char *msg; |
|
23298
5a6be8fa8de2
_PyObject_DebugCheckAddress(): If the leading pad bytes are corrupt,
Tim Peters <tim.peters@gmail.com>
parents:
23159
diff
changeset
|
1085 ulong nbytes; |
|
5a6be8fa8de2
_PyObject_DebugCheckAddress(): If the leading pad bytes are corrupt,
Tim Peters <tim.peters@gmail.com>
parents:
23159
diff
changeset
|
1086 const uchar *tail; |
|
22614
f294fdd18b5b
PYMALLOC_DEBUG routines: The "check API family" gimmick was going nowhere
Tim Peters <tim.peters@gmail.com>
parents:
22487
diff
changeset
|
1087 int i; |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1088 |
|
22614
f294fdd18b5b
PYMALLOC_DEBUG routines: The "check API family" gimmick was going nowhere
Tim Peters <tim.peters@gmail.com>
parents:
22487
diff
changeset
|
1089 if (p == NULL) { |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1090 msg = "didn't expect a NULL pointer"; |
|
22614
f294fdd18b5b
PYMALLOC_DEBUG routines: The "check API family" gimmick was going nowhere
Tim Peters <tim.peters@gmail.com>
parents:
22487
diff
changeset
|
1091 goto error; |
|
f294fdd18b5b
PYMALLOC_DEBUG routines: The "check API family" gimmick was going nowhere
Tim Peters <tim.peters@gmail.com>
parents:
22487
diff
changeset
|
1092 } |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1093 |
|
23298
5a6be8fa8de2
_PyObject_DebugCheckAddress(): If the leading pad bytes are corrupt,
Tim Peters <tim.peters@gmail.com>
parents:
23159
diff
changeset
|
1094 /* Check the stuff at the start of p first: if there's underwrite |
|
5a6be8fa8de2
_PyObject_DebugCheckAddress(): If the leading pad bytes are corrupt,
Tim Peters <tim.peters@gmail.com>
parents:
23159
diff
changeset
|
1095 * corruption, the number-of-bytes field may be nuts, and checking |
|
5a6be8fa8de2
_PyObject_DebugCheckAddress(): If the leading pad bytes are corrupt,
Tim Peters <tim.peters@gmail.com>
parents:
23159
diff
changeset
|
1096 * the tail could lead to a segfault then. |
|
5a6be8fa8de2
_PyObject_DebugCheckAddress(): If the leading pad bytes are corrupt,
Tim Peters <tim.peters@gmail.com>
parents:
23159
diff
changeset
|
1097 */ |
|
22614
f294fdd18b5b
PYMALLOC_DEBUG routines: The "check API family" gimmick was going nowhere
Tim Peters <tim.peters@gmail.com>
parents:
22487
diff
changeset
|
1098 for (i = 4; i >= 1; --i) { |
|
22986
298a7c51d2c0
PYMALLOC_{CLEAN, DEAD, FORBIDDEN}BYTE symbols: remove the PYMALLOC_
Tim Peters <tim.peters@gmail.com>
parents:
22983
diff
changeset
|
1099 if (*(q-i) != FORBIDDENBYTE) { |
|
22614
f294fdd18b5b
PYMALLOC_DEBUG routines: The "check API family" gimmick was going nowhere
Tim Peters <tim.peters@gmail.com>
parents:
22487
diff
changeset
|
1100 msg = "bad leading pad byte"; |
|
f294fdd18b5b
PYMALLOC_DEBUG routines: The "check API family" gimmick was going nowhere
Tim Peters <tim.peters@gmail.com>
parents:
22487
diff
changeset
|
1101 goto error; |
|
f294fdd18b5b
PYMALLOC_DEBUG routines: The "check API family" gimmick was going nowhere
Tim Peters <tim.peters@gmail.com>
parents:
22487
diff
changeset
|
1102 } |
|
f294fdd18b5b
PYMALLOC_DEBUG routines: The "check API family" gimmick was going nowhere
Tim Peters <tim.peters@gmail.com>
parents:
22487
diff
changeset
|
1103 } |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1104 |
|
23298
5a6be8fa8de2
_PyObject_DebugCheckAddress(): If the leading pad bytes are corrupt,
Tim Peters <tim.peters@gmail.com>
parents:
23159
diff
changeset
|
1105 nbytes = read4(q-8); |
|
5a6be8fa8de2
_PyObject_DebugCheckAddress(): If the leading pad bytes are corrupt,
Tim Peters <tim.peters@gmail.com>
parents:
23159
diff
changeset
|
1106 tail = q + nbytes; |
|
5a6be8fa8de2
_PyObject_DebugCheckAddress(): If the leading pad bytes are corrupt,
Tim Peters <tim.peters@gmail.com>
parents:
23159
diff
changeset
|
1107 for (i = 0; i < 4; ++i) { |
|
5a6be8fa8de2
_PyObject_DebugCheckAddress(): If the leading pad bytes are corrupt,
Tim Peters <tim.peters@gmail.com>
parents:
23159
diff
changeset
|
1108 if (tail[i] != FORBIDDENBYTE) { |
|
5a6be8fa8de2
_PyObject_DebugCheckAddress(): If the leading pad bytes are corrupt,
Tim Peters <tim.peters@gmail.com>
parents:
23159
diff
changeset
|
1109 msg = "bad trailing pad byte"; |
|
5a6be8fa8de2
_PyObject_DebugCheckAddress(): If the leading pad bytes are corrupt,
Tim Peters <tim.peters@gmail.com>
parents:
23159
diff
changeset
|
1110 goto error; |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1111 } |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1112 } |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1113 |
|
22614
f294fdd18b5b
PYMALLOC_DEBUG routines: The "check API family" gimmick was going nowhere
Tim Peters <tim.peters@gmail.com>
parents:
22487
diff
changeset
|
1114 return; |
|
f294fdd18b5b
PYMALLOC_DEBUG routines: The "check API family" gimmick was going nowhere
Tim Peters <tim.peters@gmail.com>
parents:
22487
diff
changeset
|
1115 |
|
f294fdd18b5b
PYMALLOC_DEBUG routines: The "check API family" gimmick was going nowhere
Tim Peters <tim.peters@gmail.com>
parents:
22487
diff
changeset
|
1116 error: |
|
22983
1c26a3106653
Move PyObject_Malloc and PyObject_Free here from object.c. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22948
diff
changeset
|
1117 _PyObject_DebugDumpAddress(p); |
|
22614
f294fdd18b5b
PYMALLOC_DEBUG routines: The "check API family" gimmick was going nowhere
Tim Peters <tim.peters@gmail.com>
parents:
22487
diff
changeset
|
1118 Py_FatalError(msg); |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1119 } |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1120 |
|
22724
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1121 /* Display info to stderr about the memory block at p. */ |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1122 void |
|
22983
1c26a3106653
Move PyObject_Malloc and PyObject_Free here from object.c. Remove
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22948
diff
changeset
|
1123 _PyObject_DebugDumpAddress(const void *p) |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1124 { |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1125 const uchar *q = (const uchar *)p; |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1126 const uchar *tail; |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1127 ulong nbytes, serial; |
|
22614
f294fdd18b5b
PYMALLOC_DEBUG routines: The "check API family" gimmick was going nowhere
Tim Peters <tim.peters@gmail.com>
parents:
22487
diff
changeset
|
1128 int i; |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1129 |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1130 fprintf(stderr, "Debug memory block at address p=%p:\n", p); |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1131 if (p == NULL) |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1132 return; |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1133 |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1134 nbytes = read4(q-8); |
|
22987
c8d61ff1c0d6
_PyObject_DebugDumpAddress(): clarify an output message.
Tim Peters <tim.peters@gmail.com>
parents:
22986
diff
changeset
|
1135 fprintf(stderr, " %lu bytes originally requested\n", nbytes); |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1136 |
|
23298
5a6be8fa8de2
_PyObject_DebugCheckAddress(): If the leading pad bytes are corrupt,
Tim Peters <tim.peters@gmail.com>
parents:
23159
diff
changeset
|
1137 /* In case this is nuts, check the leading pad bytes first. */ |
|
5a6be8fa8de2
_PyObject_DebugCheckAddress(): If the leading pad bytes are corrupt,
Tim Peters <tim.peters@gmail.com>
parents:
23159
diff
changeset
|
1138 fputs(" The 4 pad bytes at p-4 are ", stderr); |
|
22986
298a7c51d2c0
PYMALLOC_{CLEAN, DEAD, FORBIDDEN}BYTE symbols: remove the PYMALLOC_
Tim Peters <tim.peters@gmail.com>
parents:
22983
diff
changeset
|
1139 if (*(q-4) == FORBIDDENBYTE && |
|
298a7c51d2c0
PYMALLOC_{CLEAN, DEAD, FORBIDDEN}BYTE symbols: remove the PYMALLOC_
Tim Peters <tim.peters@gmail.com>
parents:
22983
diff
changeset
|
1140 *(q-3) == FORBIDDENBYTE && |
|
298a7c51d2c0
PYMALLOC_{CLEAN, DEAD, FORBIDDEN}BYTE symbols: remove the PYMALLOC_
Tim Peters <tim.peters@gmail.com>
parents:
22983
diff
changeset
|
1141 *(q-2) == FORBIDDENBYTE && |
|
298a7c51d2c0
PYMALLOC_{CLEAN, DEAD, FORBIDDEN}BYTE symbols: remove the PYMALLOC_
Tim Peters <tim.peters@gmail.com>
parents:
22983
diff
changeset
|
1142 *(q-1) == FORBIDDENBYTE) { |
|
23298
5a6be8fa8de2
_PyObject_DebugCheckAddress(): If the leading pad bytes are corrupt,
Tim Peters <tim.peters@gmail.com>
parents:
23159
diff
changeset
|
1143 fputs("FORBIDDENBYTE, as expected.\n", stderr); |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1144 } |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1145 else { |
|
22986
298a7c51d2c0
PYMALLOC_{CLEAN, DEAD, FORBIDDEN}BYTE symbols: remove the PYMALLOC_
Tim Peters <tim.peters@gmail.com>
parents:
22983
diff
changeset
|
1146 fprintf(stderr, "not all FORBIDDENBYTE (0x%02x):\n", |
|
298a7c51d2c0
PYMALLOC_{CLEAN, DEAD, FORBIDDEN}BYTE symbols: remove the PYMALLOC_
Tim Peters <tim.peters@gmail.com>
parents:
22983
diff
changeset
|
1147 FORBIDDENBYTE); |
|
22614
f294fdd18b5b
PYMALLOC_DEBUG routines: The "check API family" gimmick was going nowhere
Tim Peters <tim.peters@gmail.com>
parents:
22487
diff
changeset
|
1148 for (i = 4; i >= 1; --i) { |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1149 const uchar byte = *(q-i); |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1150 fprintf(stderr, " at p-%d: 0x%02x", i, byte); |
|
22986
298a7c51d2c0
PYMALLOC_{CLEAN, DEAD, FORBIDDEN}BYTE symbols: remove the PYMALLOC_
Tim Peters <tim.peters@gmail.com>
parents:
22983
diff
changeset
|
1151 if (byte != FORBIDDENBYTE) |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1152 fputs(" *** OUCH", stderr); |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1153 fputc('\n', stderr); |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1154 } |
|
23298
5a6be8fa8de2
_PyObject_DebugCheckAddress(): If the leading pad bytes are corrupt,
Tim Peters <tim.peters@gmail.com>
parents:
23159
diff
changeset
|
1155 |
|
5a6be8fa8de2
_PyObject_DebugCheckAddress(): If the leading pad bytes are corrupt,
Tim Peters <tim.peters@gmail.com>
parents:
23159
diff
changeset
|
1156 fputs(" Because memory is corrupted at the start, the " |
|
5a6be8fa8de2
_PyObject_DebugCheckAddress(): If the leading pad bytes are corrupt,
Tim Peters <tim.peters@gmail.com>
parents:
23159
diff
changeset
|
1157 "count of bytes requested\n" |
|
5a6be8fa8de2
_PyObject_DebugCheckAddress(): If the leading pad bytes are corrupt,
Tim Peters <tim.peters@gmail.com>
parents:
23159
diff
changeset
|
1158 " may be bogus, and checking the trailing pad " |
|
5a6be8fa8de2
_PyObject_DebugCheckAddress(): If the leading pad bytes are corrupt,
Tim Peters <tim.peters@gmail.com>
parents:
23159
diff
changeset
|
1159 "bytes may segfault.\n", stderr); |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1160 } |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1161 |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1162 tail = q + nbytes; |
|
23298
5a6be8fa8de2
_PyObject_DebugCheckAddress(): If the leading pad bytes are corrupt,
Tim Peters <tim.peters@gmail.com>
parents:
23159
diff
changeset
|
1163 fprintf(stderr, " The 4 pad bytes at tail=%p are ", tail); |
|
22986
298a7c51d2c0
PYMALLOC_{CLEAN, DEAD, FORBIDDEN}BYTE symbols: remove the PYMALLOC_
Tim Peters <tim.peters@gmail.com>
parents:
22983
diff
changeset
|
1164 if (tail[0] == FORBIDDENBYTE && |
|
298a7c51d2c0
PYMALLOC_{CLEAN, DEAD, FORBIDDEN}BYTE symbols: remove the PYMALLOC_
Tim Peters <tim.peters@gmail.com>
parents:
22983
diff
changeset
|
1165 tail[1] == FORBIDDENBYTE && |
|
298a7c51d2c0
PYMALLOC_{CLEAN, DEAD, FORBIDDEN}BYTE symbols: remove the PYMALLOC_
Tim Peters <tim.peters@gmail.com>
parents:
22983
diff
changeset
|
1166 tail[2] == FORBIDDENBYTE && |
|
298a7c51d2c0
PYMALLOC_{CLEAN, DEAD, FORBIDDEN}BYTE symbols: remove the PYMALLOC_
Tim Peters <tim.peters@gmail.com>
parents:
22983
diff
changeset
|
1167 tail[3] == FORBIDDENBYTE) { |
|
23298
5a6be8fa8de2
_PyObject_DebugCheckAddress(): If the leading pad bytes are corrupt,
Tim Peters <tim.peters@gmail.com>
parents:
23159
diff
changeset
|
1168 fputs("FORBIDDENBYTE, as expected.\n", stderr); |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1169 } |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1170 else { |
|
22986
298a7c51d2c0
PYMALLOC_{CLEAN, DEAD, FORBIDDEN}BYTE symbols: remove the PYMALLOC_
Tim Peters <tim.peters@gmail.com>
parents:
22983
diff
changeset
|
1171 fprintf(stderr, "not all FORBIDDENBYTE (0x%02x):\n", |
|
298a7c51d2c0
PYMALLOC_{CLEAN, DEAD, FORBIDDEN}BYTE symbols: remove the PYMALLOC_
Tim Peters <tim.peters@gmail.com>
parents:
22983
diff
changeset
|
1172 FORBIDDENBYTE); |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1173 for (i = 0; i < 4; ++i) { |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1174 const uchar byte = tail[i]; |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1175 fprintf(stderr, " at tail+%d: 0x%02x", |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1176 i, byte); |
|
22986
298a7c51d2c0
PYMALLOC_{CLEAN, DEAD, FORBIDDEN}BYTE symbols: remove the PYMALLOC_
Tim Peters <tim.peters@gmail.com>
parents:
22983
diff
changeset
|
1177 if (byte != FORBIDDENBYTE) |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1178 fputs(" *** OUCH", stderr); |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1179 fputc('\n', stderr); |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1180 } |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1181 } |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1182 |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1183 serial = read4(tail+4); |
|
23298
5a6be8fa8de2
_PyObject_DebugCheckAddress(): If the leading pad bytes are corrupt,
Tim Peters <tim.peters@gmail.com>
parents:
23159
diff
changeset
|
1184 fprintf(stderr, " The block was made by call #%lu to " |
|
5a6be8fa8de2
_PyObject_DebugCheckAddress(): If the leading pad bytes are corrupt,
Tim Peters <tim.peters@gmail.com>
parents:
23159
diff
changeset
|
1185 "debug malloc/realloc.\n", serial); |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1186 |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1187 if (nbytes > 0) { |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1188 int i = 0; |
|
23298
5a6be8fa8de2
_PyObject_DebugCheckAddress(): If the leading pad bytes are corrupt,
Tim Peters <tim.peters@gmail.com>
parents:
23159
diff
changeset
|
1189 fputs(" Data at p:", stderr); |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1190 /* print up to 8 bytes at the start */ |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1191 while (q < tail && i < 8) { |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1192 fprintf(stderr, " %02x", *q); |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1193 ++i; |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1194 ++q; |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1195 } |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1196 /* and up to 8 at the end */ |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1197 if (q < tail) { |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1198 if (tail - q > 8) { |
|
22484
ffcb2fd2947e
Minor code cleanup -- no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
22479
diff
changeset
|
1199 fputs(" ...", stderr); |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1200 q = tail - 8; |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1201 } |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1202 while (q < tail) { |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1203 fprintf(stderr, " %02x", *q); |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1204 ++q; |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1205 } |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1206 } |
|
22484
ffcb2fd2947e
Minor code cleanup -- no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
22479
diff
changeset
|
1207 fputc('\n', stderr); |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1208 } |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1209 } |
|
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1210 |
|
22837
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1211 static ulong |
|
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1212 printone(const char* msg, ulong value) |
|
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1213 { |
|
22860
04367cff8689
Minor improvements to the stats output dump, including adding commas to
Tim Peters <tim.peters@gmail.com>
parents:
22838
diff
changeset
|
1214 int i, k; |
|
04367cff8689
Minor improvements to the stats output dump, including adding commas to
Tim Peters <tim.peters@gmail.com>
parents:
22838
diff
changeset
|
1215 char buf[100]; |
|
04367cff8689
Minor improvements to the stats output dump, including adding commas to
Tim Peters <tim.peters@gmail.com>
parents:
22838
diff
changeset
|
1216 ulong origvalue = value; |
|
22837
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1217 |
|
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1218 fputs(msg, stderr); |
|
22860
04367cff8689
Minor improvements to the stats output dump, including adding commas to
Tim Peters <tim.peters@gmail.com>
parents:
22838
diff
changeset
|
1219 for (i = (int)strlen(msg); i < 35; ++i) |
|
22837
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1220 fputc(' ', stderr); |
|
22860
04367cff8689
Minor improvements to the stats output dump, including adding commas to
Tim Peters <tim.peters@gmail.com>
parents:
22838
diff
changeset
|
1221 fputc('=', stderr); |
|
04367cff8689
Minor improvements to the stats output dump, including adding commas to
Tim Peters <tim.peters@gmail.com>
parents:
22838
diff
changeset
|
1222 |
|
04367cff8689
Minor improvements to the stats output dump, including adding commas to
Tim Peters <tim.peters@gmail.com>
parents:
22838
diff
changeset
|
1223 /* Write the value with commas. */ |
|
04367cff8689
Minor improvements to the stats output dump, including adding commas to
Tim Peters <tim.peters@gmail.com>
parents:
22838
diff
changeset
|
1224 i = 22; |
|
04367cff8689
Minor improvements to the stats output dump, including adding commas to
Tim Peters <tim.peters@gmail.com>
parents:
22838
diff
changeset
|
1225 buf[i--] = '\0'; |
|
04367cff8689
Minor improvements to the stats output dump, including adding commas to
Tim Peters <tim.peters@gmail.com>
parents:
22838
diff
changeset
|
1226 buf[i--] = '\n'; |
|
04367cff8689
Minor improvements to the stats output dump, including adding commas to
Tim Peters <tim.peters@gmail.com>
parents:
22838
diff
changeset
|
1227 k = 3; |
|
04367cff8689
Minor improvements to the stats output dump, including adding commas to
Tim Peters <tim.peters@gmail.com>
parents:
22838
diff
changeset
|
1228 do { |
|
04367cff8689
Minor improvements to the stats output dump, including adding commas to
Tim Peters <tim.peters@gmail.com>
parents:
22838
diff
changeset
|
1229 ulong nextvalue = value / 10UL; |
|
04367cff8689
Minor improvements to the stats output dump, including adding commas to
Tim Peters <tim.peters@gmail.com>
parents:
22838
diff
changeset
|
1230 uint digit = value - nextvalue * 10UL; |
|
04367cff8689
Minor improvements to the stats output dump, including adding commas to
Tim Peters <tim.peters@gmail.com>
parents:
22838
diff
changeset
|
1231 value = nextvalue; |
|
04367cff8689
Minor improvements to the stats output dump, including adding commas to
Tim Peters <tim.peters@gmail.com>
parents:
22838
diff
changeset
|
1232 buf[i--] = (char)(digit + '0'); |
|
04367cff8689
Minor improvements to the stats output dump, including adding commas to
Tim Peters <tim.peters@gmail.com>
parents:
22838
diff
changeset
|
1233 --k; |
|
04367cff8689
Minor improvements to the stats output dump, including adding commas to
Tim Peters <tim.peters@gmail.com>
parents:
22838
diff
changeset
|
1234 if (k == 0 && value && i >= 0) { |
|
04367cff8689
Minor improvements to the stats output dump, including adding commas to
Tim Peters <tim.peters@gmail.com>
parents:
22838
diff
changeset
|
1235 k = 3; |
|
04367cff8689
Minor improvements to the stats output dump, including adding commas to
Tim Peters <tim.peters@gmail.com>
parents:
22838
diff
changeset
|
1236 buf[i--] = ','; |
|
04367cff8689
Minor improvements to the stats output dump, including adding commas to
Tim Peters <tim.peters@gmail.com>
parents:
22838
diff
changeset
|
1237 } |
|
04367cff8689
Minor improvements to the stats output dump, including adding commas to
Tim Peters <tim.peters@gmail.com>
parents:
22838
diff
changeset
|
1238 } while (value && i >= 0); |
|
04367cff8689
Minor improvements to the stats output dump, including adding commas to
Tim Peters <tim.peters@gmail.com>
parents:
22838
diff
changeset
|
1239 |
|
04367cff8689
Minor improvements to the stats output dump, including adding commas to
Tim Peters <tim.peters@gmail.com>
parents:
22838
diff
changeset
|
1240 while (i >= 0) |
|
04367cff8689
Minor improvements to the stats output dump, including adding commas to
Tim Peters <tim.peters@gmail.com>
parents:
22838
diff
changeset
|
1241 buf[i--] = ' '; |
|
04367cff8689
Minor improvements to the stats output dump, including adding commas to
Tim Peters <tim.peters@gmail.com>
parents:
22838
diff
changeset
|
1242 fputs(buf, stderr); |
|
04367cff8689
Minor improvements to the stats output dump, including adding commas to
Tim Peters <tim.peters@gmail.com>
parents:
22838
diff
changeset
|
1243 |
|
04367cff8689
Minor improvements to the stats output dump, including adding commas to
Tim Peters <tim.peters@gmail.com>
parents:
22838
diff
changeset
|
1244 return origvalue; |
|
22837
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1245 } |
|
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1246 |
|
23159
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
1247 /* Print summary info to stderr about the state of pymalloc's structures. |
|
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
1248 * In Py_DEBUG mode, also perform some expensive internal consistency |
|
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
1249 * checks. |
|
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
1250 */ |
|
22724
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1251 void |
|
23020
e2848618bd19
_PyObject_DebugDumpStats: renamed to _PyObject_DebugMallocStats.
Tim Peters <tim.peters@gmail.com>
parents:
23009
diff
changeset
|
1252 _PyObject_DebugMallocStats(void) |
|
22724
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1253 { |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1254 uint i; |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1255 const uint numclasses = SMALL_REQUEST_THRESHOLD >> ALIGNMENT_SHIFT; |
|
22837
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1256 /* # of pools, allocated blocks, and free blocks per class index */ |
|
22724
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1257 ulong numpools[SMALL_REQUEST_THRESHOLD >> ALIGNMENT_SHIFT]; |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1258 ulong numblocks[SMALL_REQUEST_THRESHOLD >> ALIGNMENT_SHIFT]; |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1259 ulong numfreeblocks[SMALL_REQUEST_THRESHOLD >> ALIGNMENT_SHIFT]; |
|
22837
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1260 /* total # of allocated bytes in used and full pools */ |
|
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1261 ulong allocated_bytes = 0; |
|
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1262 /* total # of available bytes in used pools */ |
|
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1263 ulong available_bytes = 0; |
|
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1264 /* # of free pools + pools not yet carved out of current arena */ |
|
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1265 uint numfreepools = 0; |
|
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1266 /* # of bytes for arena alignment padding */ |
|
23009
8be6238748c4
Small anal correctness tweaks:
Tim Peters <tim.peters@gmail.com>
parents:
22988
diff
changeset
|
1267 ulong arena_alignment = 0; |
|
22837
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1268 /* # of bytes in used and full pools used for pool_headers */ |
|
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1269 ulong pool_header_bytes = 0; |
|
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1270 /* # of bytes in used and full pools wasted due to quantization, |
|
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1271 * i.e. the necessarily leftover space at the ends of used and |
|
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1272 * full pools. |
|
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1273 */ |
|
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1274 ulong quantization = 0; |
|
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1275 /* running total -- should equal narenas * ARENA_SIZE */ |
|
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1276 ulong total; |
|
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1277 char buf[128]; |
|
22724
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1278 |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1279 fprintf(stderr, "Small block threshold = %d, in %u size classes.\n", |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1280 SMALL_REQUEST_THRESHOLD, numclasses); |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1281 |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1282 for (i = 0; i < numclasses; ++i) |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1283 numpools[i] = numblocks[i] = numfreeblocks[i] = 0; |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1284 |
|
22743
7361ec88188a
Fixed errors in two comments.
Tim Peters <tim.peters@gmail.com>
parents:
22741
diff
changeset
|
1285 /* Because full pools aren't linked to from anything, it's easiest |
|
7361ec88188a
Fixed errors in two comments.
Tim Peters <tim.peters@gmail.com>
parents:
22741
diff
changeset
|
1286 * to march over all the arenas. If we're lucky, most of the memory |
|
7361ec88188a
Fixed errors in two comments.
Tim Peters <tim.peters@gmail.com>
parents:
22741
diff
changeset
|
1287 * will be living in full pools -- would be a shame to miss them. |
|
22724
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1288 */ |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1289 for (i = 0; i < narenas; ++i) { |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1290 uint poolsinarena; |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1291 uint j; |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1292 uptr base = arenas[i]; |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1293 |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1294 /* round up to pool alignment */ |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1295 poolsinarena = ARENA_SIZE / POOL_SIZE; |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1296 if (base & (uptr)POOL_SIZE_MASK) { |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1297 --poolsinarena; |
|
22837
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1298 arena_alignment += POOL_SIZE; |
|
22724
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1299 base &= ~(uptr)POOL_SIZE_MASK; |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1300 base += POOL_SIZE; |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1301 } |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1302 |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1303 if (i == narenas - 1) { |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1304 /* current arena may have raw memory at the end */ |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1305 numfreepools += nfreepools; |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1306 poolsinarena -= nfreepools; |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1307 } |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1308 |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1309 /* visit every pool in the arena */ |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1310 for (j = 0; j < poolsinarena; ++j, base += POOL_SIZE) { |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1311 poolp p = (poolp)base; |
|
23159
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
1312 const uint sz = p->szidx; |
|
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
1313 uint freeblocks; |
|
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
1314 |
|
22724
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1315 if (p->ref.count == 0) { |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1316 /* currently unused */ |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1317 ++numfreepools; |
|
23159
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
1318 assert(pool_is_in_list(p, freepools)); |
|
22724
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1319 continue; |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1320 } |
|
23159
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
1321 ++numpools[sz]; |
|
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
1322 numblocks[sz] += p->ref.count; |
|
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
1323 freeblocks = NUMBLOCKS(sz) - p->ref.count; |
|
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
1324 numfreeblocks[sz] += freeblocks; |
|
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
1325 #ifdef Py_DEBUG |
|
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
1326 if (freeblocks > 0) |
|
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
1327 assert(pool_is_in_list(p, usedpools[sz + sz])); |
|
fca379c30906
_PyObject_DebugMallocStats(): Added some potentially expensive internal
Tim Peters <tim.peters@gmail.com>
parents:
23158
diff
changeset
|
1328 #endif |
|
22724
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1329 } |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1330 } |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1331 |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1332 fputc('\n', stderr); |
|
22860
04367cff8689
Minor improvements to the stats output dump, including adding commas to
Tim Peters <tim.peters@gmail.com>
parents:
22838
diff
changeset
|
1333 fputs("class size num pools blocks in use avail blocks\n" |
|
04367cff8689
Minor improvements to the stats output dump, including adding commas to
Tim Peters <tim.peters@gmail.com>
parents:
22838
diff
changeset
|
1334 "----- ---- --------- ------------- ------------\n", |
|
22724
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1335 stderr); |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1336 |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1337 for (i = 0; i < numclasses; ++i) { |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1338 ulong p = numpools[i]; |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1339 ulong b = numblocks[i]; |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1340 ulong f = numfreeblocks[i]; |
|
22836
f1f57bf09092
Widespread, but mostly in _PyMalloc_Malloc: optimize away all expensive
Tim Peters <tim.peters@gmail.com>
parents:
22795
diff
changeset
|
1341 uint size = INDEX2SIZE(i); |
|
22724
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1342 if (p == 0) { |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1343 assert(b == 0 && f == 0); |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1344 continue; |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1345 } |
|
22860
04367cff8689
Minor improvements to the stats output dump, including adding commas to
Tim Peters <tim.peters@gmail.com>
parents:
22838
diff
changeset
|
1346 fprintf(stderr, "%5u %6u %11lu %15lu %13lu\n", |
|
22724
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1347 i, size, p, b, f); |
|
22837
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1348 allocated_bytes += b * size; |
|
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1349 available_bytes += f * size; |
|
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1350 pool_header_bytes += p * POOL_OVERHEAD; |
|
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1351 quantization += p * ((POOL_SIZE - POOL_OVERHEAD) % size); |
|
22724
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1352 } |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1353 fputc('\n', stderr); |
|
23020
e2848618bd19
_PyObject_DebugDumpStats: renamed to _PyObject_DebugMallocStats.
Tim Peters <tim.peters@gmail.com>
parents:
23009
diff
changeset
|
1354 (void)printone("# times object malloc called", serialno); |
|
22837
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1355 |
|
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1356 PyOS_snprintf(buf, sizeof(buf), |
|
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1357 "%u arenas * %d bytes/arena", narenas, ARENA_SIZE); |
|
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1358 (void)printone(buf, (ulong)narenas * ARENA_SIZE); |
|
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1359 |
|
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1360 fputc('\n', stderr); |
|
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1361 |
|
22860
04367cff8689
Minor improvements to the stats output dump, including adding commas to
Tim Peters <tim.peters@gmail.com>
parents:
22838
diff
changeset
|
1362 total = printone("# bytes in allocated blocks", allocated_bytes); |
|
23020
e2848618bd19
_PyObject_DebugDumpStats: renamed to _PyObject_DebugMallocStats.
Tim Peters <tim.peters@gmail.com>
parents:
23009
diff
changeset
|
1363 total += printone("# bytes in available blocks", available_bytes); |
|
22860
04367cff8689
Minor improvements to the stats output dump, including adding commas to
Tim Peters <tim.peters@gmail.com>
parents:
22838
diff
changeset
|
1364 |
|
22837
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1365 PyOS_snprintf(buf, sizeof(buf), |
|
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1366 "%u unused pools * %d bytes", numfreepools, POOL_SIZE); |
|
22860
04367cff8689
Minor improvements to the stats output dump, including adding commas to
Tim Peters <tim.peters@gmail.com>
parents:
22838
diff
changeset
|
1367 total += printone(buf, (ulong)numfreepools * POOL_SIZE); |
|
22837
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1368 |
|
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1369 total += printone("# bytes lost to pool headers", pool_header_bytes); |
|
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1370 total += printone("# bytes lost to quantization", quantization); |
|
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1371 total += printone("# bytes lost to arena alignment", arena_alignment); |
|
ef2fbce71736
_PyMalloc_DebugDumpStats(): vastly improved the output, and it now
Tim Peters <tim.peters@gmail.com>
parents:
22836
diff
changeset
|
1372 (void)printone("Total", total); |
|
22724
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1373 } |
|
9baa8c9a1e84
New PYMALLOC_DEBUG function void _PyMalloc_DebugDumpStats(void).
Tim Peters <tim.peters@gmail.com>
parents:
22701
diff
changeset
|
1374 |
|
22479
fb45791150d1
Give Python a debug-mode pymalloc, much as sketched on Python-Dev.
Tim Peters <tim.peters@gmail.com>
parents:
22470
diff
changeset
|
1375 #endif /* PYMALLOC_DEBUG */ |
